Title: Introduction to SAS
1Introduction to SAS
Paul von Hippel Department of Sociology Ohio
State University October 22, 2004
2Topics
- Getting started
- Getting data in
- Manipulating data
- Graphics
- Analysis
- Getting results out
- Reducing repeated code
3I. Getting Started
- Logging in
- Opening SAS
- SAS windows
4Logging in to the SIL
- Turn on computer
- Enter your user name
- If your OSU email is buendia.100_at_osu.edu
- then your SIL user name is buendia.100
- not the same as in SRL
- Enter your password
- your first initial last 4 digits of your SS
your last initial - e.g., Jose Arcadio Buendia, SS 100-10-0100
- password j0100b
- again not the same as in SRL
5Opening SAS (in the SIL)
- Lower left corner, click Start
- Choose
- Programs
- Analysis
- SAS V8
6SAS windows
- Choose Window?Tile Horizontally
Type code
Submitted code ERRORs, WARNINGs, benign feedback
See output
7Saving code
- Name the contents of the Editor window
- currently blank
- Select the editor window
- Choose File?Save as
- X\brownbag.sas
- Save regularly
8II. Getting data in
- The DATA step
- - with DATALINES
- - with INFILE
- The IMPORT procedure
9DATA step with DATALINES
Type in Editor window
10(A word on DATA steps)
Basic structure DATA datasetname RUN
Each statement ends with a semicolon INPUT
describes the format character variables
followed by DATALINES introduces the data. /
comments enclosed /
11Submitting code
Highlight and submit code
12Viewing dataThe PRINT procedure
13(A word on PROCEDURES)
Basic structure PROC procedure
DATAdataset RUN Each statement ends
with a semicolon E.g., PROC print
DATAMissAmericas RUN
14DATA step with DATALINES
If you have a lot of lines, typing DATALINES is
inconvenient.
15DATA step with INFILE
16The IMPORT procedure
If there are a lot of variables in different
formats, the INPUT statement can be cumbersome
IMPORT figures out the variable types (numeric,
character, etc.) and takes variable names (Year,
Name, etc.) from the first row.
17Where is the data?
- Data file Missamericas
- Library Work (default)
- Work is a temporary folder on some disk
- erased when you quit SAS
18Making a permanent SAS data set
MYLIB points to X\. You could also say
X\somefolder\ or. MYLIB.missamericas is a
file on X\ If no library were specified, WORK
(temp disk space) would be assumed. Can you find
mylib and missamericas in the SAS Explorer? Can
you find missamericas.sas7bdat on the X drive?
19Retrieving a permanent SAS data set
- Quit SAS and relaunch it
- See? The contents of mylib are permanent.
20III. Manipulating data
21The DATA step with SET
Define some new variables
22IV. Graphics
23PROC GPLOT
24The UNIVARIATE commandwith the HISTOGRAM
statement
25V. Analysis
26The REG procedure
27VI. Getting results out
- The Output window
- The Output Delivery System
- The EXPORT procedure
28Save the output window
- Click in the output window
- Choose File?Save As
29Save selected results with ODS
- Every part of the output has a name
- If you know the name
- you can save that part of the output
- as a data file
- To do this, use the Output Delivery System (ODS)
30Whats the outputs name?
31Saving the output
- int_slope is a data set
- Can you find it?
32Doctoring the output
33The EXPORT procedure
- Results.xls is an Excel file.
- Can you find it?
34VII. Reducing repeated code
35Macros
- Often you need to repeat analyses
- with minor adjustments
- Instead of cutting and pasting
- use a macro
36Macros
- Basic structure
- macro choose_a_name (arg1, arg2)
- / SAS code using arg1, arg2 /
- mend
37Macros
38To learn more
- Online documentation
- wks.uts.ohio-state.edu/sasdoc/8/sashtml/onldoc.htm
- very technical
- The Little SAS Book
- in SRL, great introduction reference