Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to SAS Lecturer: Chu Bin Lin.

Similar presentations


Presentation on theme: "Introduction to SAS Lecturer: Chu Bin Lin."— Presentation transcript:

1 Introduction to SAS Lecturer: Chu Bin Lin

2 The SAS window

3 The SAS window

4 The SAS window 1. Editor 2. Log 3. Output 4. Results viewer
5. Results window 6. Explorer

5 The SAS window

6 The SAS window Two ways to run your programs: 1. 2.

7 The SAS language

8 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!

9 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.

10 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

11 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.

12 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:

13 The SAS language

14 Create a data set

15 Create a dataset I data score; input name $ chinese english math;
datalines; Wang John Mary Scott Stanley ; run;

16 Create a dataset I data score1; set score; sum=chinese+english+math;
average=(chinese+english+math)/3; run;

17 Create a dataset II DATA HW; INPUT ID NAME $ HEIGHT WEIGHT; DATALINES;
1 SEAN 2 MARY 3 PETER 4 SCOTT 5 WANG 6 JOHN 7 WENDY ; RUN;

18 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;

19 Import a dataset

20 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

21 Proc steps

22 Proc print and proc sort
1. proc print data=example; run; 2. proc sort data=example; by id;

23 Proc means proc means data= example;
var total read write math science socst; run;

24 Proc freq and proc gchart
1. proc freq data=example; tables grade; run; 2. proc gchart data=example; hbar grade ;

25 Save code and export dataset
1. Editor -> Save -> follow the wizard 2. File -> export data -> follow the wizard

26 Two more tips 1. Start from a small program. Get use to trial and error. 2. SAS help and documentation

27 Thank you for listening.


Download ppt "Introduction to SAS Lecturer: Chu Bin Lin."

Similar presentations


Ads by Google