Introduction to SAS for Windows

The first ("Tutorial") section of this document is a self-paced tutorial for you to try, to show you how to work with SAS for Windows. The remaining sections illustrate a few additional things you might wish to use at some later point.

Topics

1. Tutorial:

  1. Logon to Hebb network.. As usual, login to the network. [If you have not yet gotten your userid, work with another student.]
  2. Start SAS. From the desktop, double-click the SAS V9 icon .
  3. Windows: The SAS Window system is referred to as the "SAS Display Manager", which is largely the same on all systems. Initally, there are four main SAS windows, plus a bunch of others you can use.
    Other windows:
  4. Keyboard. Become familiar with the locations of special keys on the keyboard. Most of the standard Windows shortcut keys work as expected (e.g., Ctrl-X, Ctrl-C, Ctrl-V for Cut, Copy, Paste). See the SAS Control and Function Keys sheet. Use Ctrl-E to clear the contents of any window. Also, F9 ('keys') pops up the Keys window with the SAS key definitions. Here is a list of handy special keys:
    Home              Move to beginning of line
    End               Move to end of line
    PgDn              Move down one screen
    PgUp              Move up one screen
    Ctrl <-           Move left one word
    Ctrl ->           Move right one word
    Home              Move to beginning of line
    End               Move to end of line
    
    Ctrl-C            Copy selected text to clipboard
    Ctrl-X            Cut selected text to clipboard
    Ctrl-V            Paste from clipboard
    
    Ctrl-E            Clear window
    Ctrl-Z            Undo last action
      
    F1                Help
    F3                Submit
    F9                Show Keys window, with definitions of special keys
    
  5. Menus: Like other Windows apps, SAS has the standard pull-down menus (File, Options, Windows, Help) at the top of the main SAS window.

    There is also a Menu item available by clicking in the upper left corner of the Editor, Log, or Output window and a popup menu with the same choices available by clicking the Right mouse button in these windows.

  6. Entering program steps in the Editor window. In interactive SAS, you can submit program steps from the Editor as soon as you have typed in one or more complete DATA or PROC step. SAS runs each step as soon as it knows that it is complete: when it sees (a) a new DATA step, (b) a new PROC step, or (c) a run; statement.

Getting help

You can get immediate help with SAS syntax in several ways. For a procedure, say the REG procedure, the easiest way is to type help reg in the small command window in the upper-left corner (just below the main menu).

SAS Analyst

Most of the things you can do with SAS syntax statements can be done more easily with the SAS Analyst application, a user-friendly, menu-driven interface in which you can carry out statistical analyses and create graphical displays of your data.  The Analyst application works by creating the SAS syntax from menus and dialog boxes.  

To start the Analyst application, go to the Solutions menu, choose Analysis, then Analyst.
To open a SAS dataset in a SAS library (e.g., work, psy303, psy614), go to the File menu, choose Open by SAS name, then select the library and the dataset. (Note: course libraries like psy303 and psy614 are Read-Only, so you cannot modify them or transform variables.)

For this tutorial,
  1. Open the Nations data set in the Analyst application from the work library.
  2. Explore the new Statistics menu which appears. Try Descriptive --> Distributions... for univariate summaries (the same as proc univariate gives)
  3. Explore the new Graphs menu. Try a Histogram of one variable, or a Scatterplot of two variables.

Data transformations with SAS Analyst

To make changes to the dataset in the SAS Analyst, you first have to change the mode from Browse to Edit. Select Edit --> Mode --> Edit

Once you have switched to Edit mode, you can calculate a new variable. To calculate the log of Infant Mortality Rate, for example, use the Compute option in the Transform submenu of the Data menu. The panel that appears contains all SAS functions, classified in various categories (log is in the Mathematical category).
More detailed instructions and examples are contained in the document, SAS for Windows and the Analyst Application from the University of Texas.


This is the end of the in-class lab tutorial. The notes below, for further reading, show how to do a few more things with SAS.

2. External files

More information on the topics below is available in the SAS Program Steps document and the SAS Companion for the Microsoft Windows Environment manual.

Using the Import Wizard

The Import Wizard is a convenient tool for reading in data stored in file formats other than the SAS dataset format. Simply go to the File menu and select Import data

In the first dialog box of the Import Wizard, you are asked to specify whether your data exists in a standard file format (e.g., Excel, Access, tab-delimited files, etc.)

Data files

Reading data from an external file is just like reading from data contained in the SAS file, except, use an infile statement instead of datalines;. The infile statement can give the actual DOS pathname of the external file. You can also use a filename statement to define a synonym (fileref) for the actual file.

The example below shows two equivalent ways to read data from a file on a diskette.

filename mydata 'a:\thesis.dat';
data thesis;
   infile mydata;
   input subjid group resp1-resp10;
data thesis;
   infile 'a:\thesis.dat';
   input subjid group resp1-resp10;
On the lab network, special DATA directories are pre-defined (e.g., n:\psy6140\data), containing various raw data sets for several courses. To read the data ITEMS.DAT, use the following form (.DAT is the default extension for the INFILE statement):
data items;
   infile data(items);
   input subjid group resp1-resp10;
The example below reads from a file on the network stored under a home directory (on the F: drive):
data thesis;
   infile 'f:\work\sas\sasuser\thesis.dat';
   input subjid group resp1-resp10;

SAS files

An existing SAS program/data file can be entered into the Program Editor (and then submitted) in several ways:

Using an external editor

The SAS Enhanced Editor in V8 is a big improvement over previous versions --- statements are recognized by syntax as you type, and represented on the screen (color/font) accordingly.

You can also use any other editor (e.g., Notepad) to edit SAS files then either (a) Open into Program Manager to run the program as a whole, or (b) Copy lines to the Windows clipboard. To submit lines from the clipboard, select Run -> Submit clipboard from the popup menu.

Reading SPSS files

The SPSS interface enables you to read SPSS system files directly into SAS. See Converting SAS to SPSS for converting SAS data to an SPSS file.

To read an SPSS save file, issue a LIBNAME statement that specifies the SPSS engine, in the form,

LIBNAME libref SPSS 'd:path\filename';
e.g.,
LIBNAME thesis SPSS 'f:\work\spss\thesis.dat';

You can then refer to the data in any PROC/DATA step as follows:

proc print data=thesis._first_;
(You can use any name you like instead of _first_)

© 1995 Michael Friendly