Statistics 212/601/651/652/659
Guide to SAS on the PC
Following is an outline to help you run some basic SAS analyses on
the PC. I will eventually add more details on SAS procedures.
I am assuming that you have started SAS and the windows
are visible on your PC. There are three windows:
- the PROGRAM EDITOR,
which contains the SAS program;
- the SAS LOG, which tells you what SAS
has processed and any errors in the program;
- the OUTPUT window, which
contains the results of any SAS program.
Running Batch SAS
- Create a file with a .sas extension that contains your
SAS program, for example, prog.sas .
- Load the program into the PROGRAM EDITOR by clicking on the
File menu
and then on Open . Highlight prog.sas
and click on
OK .
Alternatively you can type your program into the PROGRAM EDITOR.
- To run the program, click on Locals and then on
Submit . Alternatively, click on the button with the
running figure on the tool bar.
- Check the LOG Window to see if there are any errors.
- If not, the SAS
analysis is available in the OUTPUT Window. The results should be saved
to a file, say prog.lst , by clicking on
File and then on Save As .
You can use the editor or word processor of your choice to incorporate
the output into your writeup. To get rid of output that you no longer
need, choose Edit and Clear Text .
- If there are some errors, you can recall the program by clicking
on Locals and then on
Recall Text . You can correct your errors using the
PROGRAM EDITOR. Be sure to save the corrected program by clicking on
File and then on Save .
Creating a SAS Program
The SAS programs consists of 3 parts:
- data step
- data values
- SAS procedures
SAS statements end with semicolon (; ). An asterisk
(* ) at the beginning of a SAS statement causes the
statement not to be executed and to be treated as a comment.
Following is a simple SAS program which will explained in the text:
data name;
input x y;
cards;
8 10
12 14.2
16 16.3
20 24.3
24 22.7
proc print;
proc plot; plot y*x;
proc reg; model y=x/r cli clm;
run;
Data Step
The data step defines the variables in the dataset. A basic data step is
the following:
data name;
input x y;
cards;
The following three
statements are necessary:
- data name; This says that a data set called
name is to be created.
- input x y; This says that the data will be read
in with an x value followed by a y value on each line. A character variable
name is followed by a dollar sign ($).
- cards; This says that the data values follow.
One can add expressions between the input and
cards statement to create new variables that are
functions of x and y. For example, ylog=log(y); will
create a new variable called ylog
that is the natural logarithm of y.
SAS will read only
as many values as there are variables in your input statement. It then
read values on the next line. This continues until SAS finds a program
statement.
Thus, each line in the data set will consist one observation of each of
the variables in the input list. To have more than one observation per line,
place the characters @@ before the semicolon in the
input statement.
Data Values
The data values are entered with each line consisting of a single observation
of the variables given in the input statement.
The values of the variables are separated by one or more blanks. A simple
set of data follows:
8 10
12 14.2
16 16.3
20 24.3
24 22.7
SAS Procedures
Any number of SAS procedures can be used to analyze the data. Each procedure
begins with a proc statement followed by the name of the
procedure. Following is an example of a short sequence of procedures used
for simple linear regression:
proc print;
proc plot; plot y*x;
proc reg; model y=x/r cli clm;
run;
- proc print; caused all the variables in all the
observations to be printed.
- proc plot; plot y*x; prints a scatter plot of
y versus x.
- proc reg; model y=x/r cli clm; carries out a regression
analysis with y as the response and x as a predictor. The r
option causes residuals, predicted values, and various diagnostics to be
printed. The cli option caused prediction intervals for a
single response for each value of the predictor to be printed. The
clm option caused confidence intervals for a
mean response for each value of the predictor to be printed.
- proc anova; class treat; model y=treat; carries out
a one-way analysis of variance with y as the response and treat indicating
the treatment.
- run; causes SAS to execute all of your statements. If
this is omitted, the last statement in your program will not be executed.
Importing Data into SAS
SAS provides for the import of text files, Excel files, and other files.
You start out by choosing Files and then
Import Data... . The SAS Import Wizard will appear.
On this window choose the type of file such as Excel (*.xls) or tab-delimited
text file (*.txt). Then click on Next. The next box asks
for the location of the file. Either type this in or click on
Browse and find the file where you stored it on the hard drive.
After the name of the file appears in the box, click on Open
. This will take you back to the previous box. You check that
you have chosen the correct file and click on Next .
You are now asked for the SAS destination. You will usually use the
default WORK library. You enter the name of the dataset in the empty
box labelled "Member". Click on Next . You then
click on Finish which completes the importing of the
data. You can then analyze the data using either batch SAS or interactive
data analysis.
SAS INSIGHT--Interactive Data Analysis
INSIGHT provides a menu-driven approach to analyzing data. In particular,
you can obtain very good graphs using INSIGHT. You must first create the
desired data set. One way is to use a data step as above followed
by some procedure, such as proc print;. Alternatively, you
can import the data set into SAS.
Version 6.12
To start INSIGHT, choose GLOBALS followed by
ANALYZE and INTERACTIVE DATA-ANALYSIS .
To load the data set you just created, choose WORK
and then the desired dataset. INSIGHT will place your data into a spreadsheet.
Versions 8.0 and 9 To start INSIGHT, choose SOLUTIONS
followed by
ANALYSIS and INTERACTIVE DATA ANALYSIS .
To load the data set you just created, choose WORK
and then the desired dataset. INSIGHT will place your data into a spreadsheet.
To start
To create new variables from existing ones, click on the column for a given
variable. Then click on EDIT and VARIABLES
and choose the desired transformation. A new variable will be
place in the spreadsheet.
Choose the desired analysis from the ANALYZE menu.
Descriptive Statistics Using INSIGHT
The data set for the regression should be placed into INSIGHT using the above
procedure. Next choose Analyze and Distribution (Y)
. Click on any variable of interest and then on the Y
box. Continue until you have all the variables of interest. By
clicking on the Output box, you can choose additional
statistics and graphs for the output. Click OK in the
Output window. Then click OK to obtain the descriptive
statistics.
Simple Linear Regression Using INSIGHT
The data set for the regression should be placed into INSIGHT using the above
procedure. Next choose Analyze and Fit (Y X)
. A box containing all the variables in your data set will appear.
Click on the name of the response (Y variable) and then on the
Y box.
Next click on the name of the predictor (X variable) and then on the
X box.
To choose various output options, click on the Output
box. You can obtain residuals, predicted, and various diagnostic variables
by clicking on the Output Variables box.
To run the regression analysis, click on Apply .
Printing Output from INSIGHT
One can copy the output from INSIGHT into a Microsoft Word document and then
print the resulting document. First, obtain the desired analysis.
Next, hold down the left mouse button and move the cursor
over the boxes containing
the desired output. After the mouse is released, the outlines of the
selected boxes should be dark. Then choose File-Save-Graphics
File . Give the file a name (on your diskette) ending
with the "gif" extension such as trial.gif,
choose GIF and grey scale, then
OK.
Next go to the Word window. Choose Insert-Picture-From File
. Click on the desired file and OK
. The SAS analysis is now part of your Word document. You can
modify the size of the picture and its location within Word.