Introduction to SAS Lecturer: Chu Bin Lin
The SAS window
The SAS window
The SAS window 1. Editor 2. Log 3. Output 4. Results viewer 5. Results window 6. Explorer
The SAS window
The SAS window Two ways to run your programs: 1. 2.
The SAS language
The SAS language SAS programs: A SAS program is a sequence of statements executed in order. SAS statements: Every SAS statement ends with a semicolon!
The SAS language Layout of SAS programs: 1. SAS statements can be in upper- or lowercase. 2. Statements can continue on the next line (as long as you don’t split words in two). 3. Statements can be on the same line as other statements. 4. Statements can start in any column.
The SAS language Comments: There are two styles of comments you can use: 1. starts with an asterisk (*) and ends with a semicolon (;). 2. The other style starts with a slash asterisk (/*) and ends with an asterisk slash (*/). The
The SAS language SAS programs are constructed from two basic building blocks: DATA steps and PROC steps. A typical program starts with a DATA step to create a SAS data set and then passes the data to a PROC step for processing.
The SAS language Here is a simple program that converts miles to kilometers in a DATA step and prints the results with a PROC step:
The SAS language
Create a data set
Create a dataset I data score; input name $ chinese english math; datalines; Wang 67 78 98 John 78 77 95 Mary 44 91 100 Scott 67 98 85 Stanley 67 93 78 ; run;
Create a dataset I data score1; set score; sum=chinese+english+math; average=(chinese+english+math)/3; run;
Create a dataset II DATA HW; INPUT ID NAME $ HEIGHT WEIGHT; DATALINES; 1 SEAN 177 77 2 MARY 165 57 3 PETER 188 79 4 SCOTT 173 65 5 WANG 169 72 6 JOHN 180 95 7 WENDY 166 43 ; RUN;
Create a dataset II DATA HW1; SET HW; BMI= WEIGHT/((HEIGHT/100)**2); RUN; DATA FAT THIN; SET HW1; IF BMI>= 24 THEN OUTPUT FAT; IF BMI < 17 THEN OUTPUT THIN;
Import a dataset
Import a dataset Two ways to import an outside dataset 1. Use Proc statement PROC IMPORT DATAFILE = 'C:\Users\Sean\Dropbox\2016\SWJTU\SAS\example.xlsx' OUT = example REPLACE; RUN; 2. Click on pull down Menus
Proc steps
Proc print and proc sort 1. proc print data=example; run; 2. proc sort data=example; by id;
Proc means proc means data= example; var total read write math science socst; run;
Proc freq and proc gchart 1. proc freq data=example; tables grade; run; 2. proc gchart data=example; hbar grade ;
Save code and export dataset 1. Editor -> Save -> follow the wizard 2. File -> export data -> follow the wizard
Two more tips 1. Start from a small program. Get use to trial and error. 2. SAS help and documentation
Thank you for listening.