Intro to SAS lab activities - Stat 402A

advertisement
Intro to SAS lab activities - Stat 402A
Philip Dixon
This is intended to be used with the handout “Using SAS on PC’s” available on the Stat
402 website. That handout explains the concepts behind these activities. This document
directs you through running a SAS program, editing SAS programs, and how to get help.
Activities are in bold. My comments are in regular text.
Start up SAS. The icon should be on the desktop. It is a grey triangle with a yellow
arrow. The icon text should say SAS 9.1.
or Find SAS in the Start Menu/Programs list
The SAS panel has 4 windows:
Explorer: we won’t use this at all (at least for this class)
Editor: This is where you type (or copy) your SAS program
Log: This is where SAS puts errors or notes about your program
Output: This is where results go, when the program works.
Start up your favorite browser (IE, Firefox, Netscape)
Navigate to the SAS programs part of the Stat 402A web site
Open tomato2.sas
Select the program, copy it to the clipboard and paste it into the SAS editor window
(ctrl-A, ctrl-C, then ctrl-X)
you could also save the program on the hard disk or a flash drive, then open it in SAS.
Run tomato2.sas. You have three ways to run the program:
click the ‘submit’ icon. This is the running person on the SAS shortcut bar.
click the ‘submit’ menu item. Click on Run on the menu bar, then click on submit.
hit the F3 function key. This is the keyboard shortcut
you should see new text in both the log and output windows
ask for help if you don’t see the output.
Tomato2.sas reads data into a SAS data set, then draws side-by-side boxplots, does a ttest, then fits a 1-way ANOVA. More information, especially about the data step and
input statements is in the “Using SAS” handout. More information about SAS
procedures is in the “Handout on basic SAS procedures and data step programming”
Notice where the data go: after all the other commands in the data step, between the
datalines; command and the lonely ;
It can be difficult to debug SAS programs when you include the data with the program.
These data sets are small; imagine having 1000 lines of data between the data step and
the proc steps. It is easy to read data from an external file. The only problem is that SAS
does not use the My Documents folder by default.
Change the default directory to MyDocuments (or a folder in MyDocuments):
locate the text ‘C:\Documents …’ on the bottom line of the SAS window
double click on that text. A Change folder window will pop up.
Navigate to MyDocuments or a folder in MyDocuments
I recommend a folder for all your Stat 402 work. If you don’t like MyDocuments, you
can use whatever location you would like.
Use your browser to open tomato.txt then save it in your MyDocuments\Stat 402
folder.
Save tomato.sas in your MyDocuments\Stat 402 folder
Click on the Editor window, so it is highlighted, then
Click the open icon (or use file/open)
Navigate to MyDocuments\Stat 402 folder and click on tomato.sas
You should see a new window with the tomato.sas code in it.
Close the editor window with tomato2.sas
If you submit the tomato.sas code, the output and log information will be appended to
what is already there.
Clear the output and log windows: Highlight the window, then either
click the CLEAR icon (the black X next to the submit icon)
select edit/clear all from the menu bar
or type ctrl-e, the keyboard shortcut
repeat with the other window. You can also clear the editor window this way.
ctrl-Z (undo) will undo any of the above clear’s.
submit the tomato.sas code.
The output is identical; the only difference is that the data is not included with the SAS
program.
Your practice: Download the fishoil data from the class web page
modify your tomato.sas or tomato2.sas code to run a t-test comparing means of the
two fishoil treatments.
Getting help: the easiest ways are in office hours or to e-mail the contents of the log
window to me. If you are stuck for more than 15 minutes, ask for help. Other students in
the computer lab may be able to help. If not, send me an e-mail.
The best way to use e-mail is:
clear the log window (see above)
submit the program again
highlight the log window, select all the text, and paste into the body of an e-mail
message. Send that message as a plain text file (not a styled text or html file).
Use Stat 402 or something like that as the subject. I get lots of spam with HELP in the
subject line.
If you can’t remember an option, look back through previous SAS programs. They’ll all
be posted on the class web page.
Or, look at the SAS help files. To find names of options, you need the Syntax part
click on the help icon (book with ? on cover)
expand SAS Products
1) expand SAS/Stat (statistical procedures)
expand SAS/STAT Users Guide
scroll down and expand the procedure of interest (e.g. PROC TTEST)
expand Syntax
click on the statement of interest
2) or expand Base SAS (data step, simple stats)
for data step commands, then:
expand SAS Language Dictionary
expand Statements
click on the statement of interest
for simple stats procedures and utility procedures, then:
expand Procedures
click on the procedure of interest
You will find proc means, proc print, proc plot, proc import here
for proc corr, proc freq, or proc univariate,
expand SAS Procedures: CORR, FREQ, UNIVARIATE
click on the procedure of interest
these procedures are also linked to the previous Procedures list
Download