Basic SAS commands Laboratory No. 1 Computer Techniques for Biological Research

advertisement
ISU
Basic SAS commands
Laboratory No. 1
Computer Techniques for Biological
Research
Animal Science 500
Ken Stalder, Professor
Department of Animal Science
109 C Kildee Hall
ISU
Getting Started With SAS
• The Animal Science Labs already have SAS
preloaded on them
– Room 1 – generally open most of the time
– Room 124 – open except when classes are being held in
the classroom
• SAS is also available for those that have access to
a laptop computer
– Cost $8 per computer that SAS is installed on
– Encourage everyone to get this option can perform SAS
analyses where ever they are located
– Contact Mark Hawley or Ken Toft 294-5149
ISU
Starting the SAS Program
• Go to the Windows Start Button (lower left hand
corner)
ISU
Starting the SAS Program
• Click on All Programs Button
• Find SAS button and click on that
• Under the SAS button find the SAS 9.2 32 English
– The 9.2 indicates what version of SAS is installed on
this machine
– 32 means it is operating in the 32 bit environment – in
contrast to the 64 bit alternative
– English means the language used is English
ISU
Getting Started With SAS
Notice three important areas –
1. Editor 2. Log3. Explorer -
ISU
Getting Started With SAS
• Program editor window
– Commands are entered here either directly or by
opening a saved file
– Use the File menu to open as previously saved file
(file.sas) or to save your program
• Important to frequently save your program if you plan to use it
later or for some reason your computer locks up, the computer
shuts down, etc.
ISU
Getting Started With SAS
• Once command have been edited and saved, they
must be submitted
– Locals menu
– Clicking submit button
– Clicking F8
• Be sure there is a run statement ending with ; of
course at the end to the submitted text
• Important to add the quit; statement as well to be
sure your program does not result in an infinite
loop.
ISU
Getting Started With SAS
• If text within the program editor is highlighted, then
only that text is submitted when you hit the submit
button
otherwise the entire content of the
program editor will be submitted.
• All contents of the program editor are cleared when
the entire program editor contents are submitted
• If there are errors and you need to make corrections
to your program you must click on recall text within
the Editor window from the run menu or by hitting F4
while in the Editor window
ISU
Getting Started With SAS
• The Log Window
• When a program or a set of statements or code are
submitted, SAS puts messages into the log window.
• These messages describe the processing of the
submitted commands
– Error messages – describe whether data were inputted and /
or outputted correctly
• Critical errors are in red
• Less critical errors are in green
– Provide dataset names
ISU
Getting Started With SAS
• Log also tells the user when things go correctly
– All of the text is blue
– Just because there are not errors does not mean everything
is correct!
• The log window should be viewed frequently
– After every submission of code to be sure each step
proceeds correctly
• Remember SAS programming is a STEP BY STEP process
ISU
Getting Started With SAS
• The Output Window
• SAS places the results of any procedures (PROCs) in
the output window
– Means, Frequency, ANOVA, Mixed, etc.
• Remember when you identify errors in your program
but actually obtained results that were printed in the
output file, you must clear the contents of the Output
window.
• Cannot edit the contents of the output window
directly
– Export using file.lst and edit using Word, Notepad, Writer
ISU
Importing Data
• The input statement in SAS is used to read data
from a variety of sources
– Spreadsheets – imported directly even obtaining
variable names
• A variety of spreadsheets can be used to record and input data
into SAS
– Text file (txt) – data might be collected and stored as a
text file
– ASC – data can be stored or converted to a dos asc file
– Can be included as a part of your SAS program or code
• Using the CARDS or DATALINES statement;
ISU
Types of Input Statements
1. List input (free form) – data fields must be separated
by at least one blank. List the name of the variable.
Follow the name with a $ if it is a character variable.
2. Column input – follow the variable name (and $ for
character) all of the columns have associated variable
names.
3. Formatted input – can precede variable name with @
(example formats: $10. = 10 column character
variable, 6. = 6 column numeric variable)
* You can mix input styles but I do not recommend
ISU
Example Inputs
1. Importing data and variable names from an Excel
spreadsheet.
2. Using the CARDS statement and reading data
directly into the program
3. Reading an asc file.
Download