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
- Logon to Hebb network.. As usual, login to the network.
[If you have not yet gotten your userid, work with another
student.]
- Start SAS. From the desktop, double-click the SAS V9
icon
.
- 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.
- Explorer: With panes for Explorer (SAS libraries, file
shortcuts), and Results. Once you have some output, the Results
pane shows a tree-like summary of your Output Window. From the
Results pane you can select, delete or edit the procedure output
before printing or saving your results.
- Log: Your session LOG. Notes and Error messages appear
here.
- Program Editor: Enter and edit SAS program lines.
- Output: Output from SAS procedures. Initially hidden
behind the Log and Program Editor windows, this window pops to the
foreground when program output is produced.
Other windows:
- Help -The Help facility contains SAS syntax descriptions
for almost all of the SAS system (PROCs, DATA step statements,
etc.) Note that the Help button on the toolbar is more useful for
documentation than the Help menu.
- Graph - High-resolution graphs appear in their own
window. You can print or save them (one at a time).
- 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
- 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.
- 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.
- Enter the small program below. Note how words are colored as
you type.
title 'Class data set';
data class;
input name $ sex $ age height weight;
datalines;
Alfred M 14 69.0 112.5
Alice F 13 56.5 84.0
Barbara F 13 65.3 98.0
Carol F 14 62.8 102.5
Henry M 14 63.5 102.5
James M 12 57.3 83.0
Jane F 12 59.8 84.5
Janet F 15 62.5 112.5
Jeffrey M 13 62.5 84.0
John M 12 59.0 99.5
Joyce F 11 51.3 50.5
Judy F 14 64.3 90.0
;
run;
- Submit the DATA step: Raise the Program Editor menu (Right
mouse button) and select Run -> Submit , or press
F3, or click the Submit button
in the
Tool Bar.
- Add a PROC step or two:
proc corr data=class;
run;
proc reg data=class;
model weight = height;
run;
Submit
(or F3) again.
Note that each PROC or DATA step is not executed until you type
run; or submit another DATA or PROC statement.
- Editing program lines: You can edit the lines in the Program
Editor simply by overtyping. There are a variety of editing
commands available. If you select a set of lines with the mouse,
and click the submit button, only those lines are submitted.
Modify the PROC REG step to ask for a display of predicted values and
residuals, and a plot of residual vs. predicted. There are many options
you can use with most SAS procedures.
proc reg data=class;
model weight = height / p;
plot residual. * predicted.;
run;
- Printing & Saving your results: The currently
selected window (Editor, Log, Output) can be saved or printed from
the File menu. Each window must be saved or printed
separately.
- Select File -> Print to print the current
window.
- Select File -> Save As [if you have not yet
named your file] or File -> Save [if your file has
been named]. The default location is your home directory, named
with your userid, the F:\ drive.
For this tutorial,
- Save the SAS statements from the Program Editor window. Type
Tut1 in the File name: box. The statements will be
saved as Tut1.sas.
- Save the output from the Output window. Type
Tut1
in the File name: box. The statements will be saved as
Tut1.lst.
- Loading class data. Your instructor may have SAS data
files which are stored on the server. To use one, e.g., the Baseball
data, type:
%include data(baseball);
You may then proceed to do analyses with this dataset, e.g., for a
univariate display, type:
proc univariate plot data=baseball;
var salary;
histogram salary / normal;
run;
- Running class examples. Your instructor may have created
examples or SAS data files which are stored on the server. To use
one,
- select Open from the File menu.
- On the Open panel, select Drive N:, then the directory for your
course. e.g., n:\psy3030\examples\regress.
- Select a file in the File panel (e.g., therapy.sas),
then click OK. The selected file should appear in the Program
Editor window.
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,
- Open the Nations data set in the Analyst application from
the work library.
- Explore the new Statistics menu which appears.
Try Descriptive --> Distributions...
for univariate summaries (the same as proc univariate
gives)
- 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.
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:
- from the main SAS File menu, choose Open into Program Editor. A
standard file selection panel will appear. Navigate through the
Drive and Directory subwindows to select the file, then
double-click or choose OK.
- type and submit a %include statement in the Program
Editor. Several public SAS directories are predefined, one of which
is referred to as data. Access things there in this form:
%include data(fitness);
which will insert the contents of the file FITNESS.SAS. The name
DATA is a synonym (fileref) for the directory
n:\data.
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