1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products...

32
1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR, ...... etc. The most common one is SAS/BASE which provides tools for: information storage and retrieval data modification and programming report writing statistical analysis handling
  • date post

    22-Dec-2015
  • Category

    Documents

  • view

    273
  • download

    11

Transcript of 1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products...

Page 1: 1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR,...... etc. The most.

1

SASSAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR, ...... etc. The most common one is SAS/BASE which provides tools for:

information storage and retrieval

data modification and programming

report writing

statistical analysis

handling

Page 2: 1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR,...... etc. The most.

2

StructureA SAS program basically contains two parts, the DATA and the PROC.

DATA is the part which describes the data to be interpreted and the

PROC is the part which tells SAS how we want the data to be processed and analysed.

Page 3: 1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR,...... etc. The most.

3

SAS StatementEvery SAS statement ends with a semicolon. More than one SAS statement can be put on a line. The following statements:

DATA NEW ;INPUT X Y Z ;CARDS ;

could also be written as:

DATA NEW; INPUT X Y Z; CARDS;

Page 4: 1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR,...... etc. The most.

4

How to Get Data into SAS Program

There are two ways to put data into SAS program. The first method is to include the data inside the SAS program and the second method is to read data externally.

In order to get the data from a file on hard disk or diskette into a SAS data set, we need the following statements:

DATA

INFILE

INPUT

RUN

Page 5: 1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR,...... etc. The most.

5

data income;infile 'c:\income.dat';input name$ sex$ salary;run;

data income;input name$ sex$ salary;cards;George M 2300Amy F 2500Steve M 2200Tom M 4400;run;

Page 6: 1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR,...... etc. The most.

6

Input Statement

The following steps show you how to write Input Statement:

1) Begin with the word INPUT.

2) Choose the names of variables of each record.

3) If the variable is a character, put a dollar sign after it.

4) Write the number of the column where the values of the variables begin and end.

Page 7: 1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR,...... etc. The most.

7

input name$ 1-8sex$ 9-9salary;

input name$ sex$ salary;

Page 8: 1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR,...... etc. The most.

8

We may also discard certain observations by using the DELETE statement:

data income;infile 'c:\income.dat';input name$ 1-8

sex$ 9-9 salary;

if sex = 'm’ then delete;run;

Only females are selected.

Page 9: 1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR,...... etc. The most.

9

Environment

After invoking the SAS, there are three major window areas for you to work in, they are:

PROGRAM EDITOR- where you enter the SAS statements to be executed.

OUTPUT -where results output by SAS procedures are displayed.

LOG - displays messages from the SAS system as well as your SAS statements as they are executed

Page 10: 1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR,...... etc. The most.

10

Page 11: 1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR,...... etc. The most.

11

Page 12: 1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR,...... etc. The most.

12

Page 13: 1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR,...... etc. The most.

13

Page 14: 1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR,...... etc. The most.

14

Page 15: 1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR,...... etc. The most.

15

Page 16: 1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR,...... etc. The most.

16

Page 17: 1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR,...... etc. The most.

17

Page 18: 1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR,...... etc. The most.

18

Program Sample 1

When we enter the following program into the PROGRAM EDITOR area and click the execution button (the button with a running person figure) the output will be shown in the OUTPUT AREA.

data income; input n$ sex$ salary age; cards; john m 300 21 mary f 200 23 jack m 2300 25 helen f 3000 21 george m 2300 24 anna f 3000 23 ; proc print data = income; sum salary ; run;

Page 19: 1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR,...... etc. The most.

19

The following will be shown in the OUTPUT AREA after the above program is executed.

The SAS System 11:29 Friday, November 5, 1999 1

OBS N SEX SALARY AGE

1 john m 300 21 2 mary f 200 23 3 jack m 2300 25 4 helen f 3000 21 5 george m 2300 24 6 tony m 2000 24 7 vincent m 2500 22 8 anna f 3000 23 ====== 15600

When we click on the Printer Button the content in the OUTPUT AREA will be printed to the network printer.

Page 20: 1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR,...... etc. The most.

20

Program Sample2

When we execute the following program a different output will be shown. Since we have the 'nodate' option, the date is not printed. The report title is printed according to what we have put down for title1 and title2. You may have several titles. They have to be named as title1, title2, title3 and so on.options nodate;title1 'XYZ Company';title2 'Salary Report';data income;input n$ sex$ salary age;cards;john m 3000 21mary f 3000 18helen f 3000 20jack m 4500 22tony m 4500 19anna f 3000 21willie m 4500 18;proc print data = income; var n sex;run;proc freq data = income; table sex * salary;run;

Page 21: 1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR,...... etc. The most.

21

XYZ Company

Salary Report

OBS N SEX

1 john m 2 mary f 3 helen f 4 jack m 5 tony m 6 anna f 7 willie m

XYZ Company Salary Report

TABLE OF SEX BY SALARY

SEX SALARY

Frequency|Percent |Row Pct |Col Pct | 3000| 4500| Total----------------------------f | 3 | 0 | 3 | 42.86 | 0.00 | 42.86 | 100.00 | 0.00 | | 75.00 | 0.00 |---------------------------m | 1 | 3 | 4 | 14.29 | 42.86 | 57.14 | 25.00 | 75.00 | | 25.00 | 100.00 |----------------------------Total | 4 | 3 | 7 57.14 42.86 100.00

options nodate;title1 'XYZ Company';title2 'Salary Report';data income;input n$ sex$ salary age;cards;john m 3000 21mary f 3000 18helen f 3000 20jack m 4500 22tony m 4500 19anna f 3000 21willie m 4500 18;proc print data = income; var n sex;run;proc freq data = income; table sex * salary;run;

Page 22: 1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR,...... etc. The most.

22

Program Sample 3

The following program shows only the female employee data. You may notice that we have put a selection statement in our SAS program. When the value of sex is 'm' the male employee record will be removed.

options nodate;title1 'XYZ Company';title2 'Salary Report';

data income;input n$ sex$ salary age;if sex = 'm' then delete;cards;john m 3000 21mary f 3000 18helen f 3000 20jack m 4500 22tony m 4500 19anna f 3000 21willie m 4500 18;proc print data = income; var n sex salary age;run;

Page 23: 1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR,...... etc. The most.

23

XYZ Company Salary Report

OBS N SEX SALARY AGE

1 mary f 3000 18 2 helen f 3000 20 3 anna f 3000 21

options nodate;title1 'XYZ Company';title2 'Salary Report';

data income;input n$ sex$ salary age;if sex = 'm' then delete;cards;john m 3000 21mary f 3000 18helen f 3000 20jack m 4500 22tony m 4500 19anna f 3000 21willie m 4500 18;proc print data = income; var n sex salary age;run;

Page 24: 1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR,...... etc. The most.

24

Program Sample 4The following SAS program will process an external data file. The external data file is a simple text file. The content of the data file and their corresponding column locations are listed below:

Student Name - column 1 to column 10Course - column 11 to column 14Age - column 18 to column 19* column 15 to column 17 ignored

111111111212345678901234567890Albert Comp 17May Acct 16David Math 17Helen Comp 16George Acct 16Peter Phys 17Betty Math 16Cindy Eng 16Richard Acct 17Oliver Math 16

Page 25: 1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR,...... etc. The most.

25

data student;infile 'a:\student.dat';input studnam $ 1-10 course $ 11-14 age 18-19;run;

proc print data = student;run;

1111111111212345678901234567890Albert Comp 17May Acct 16David Math 17Helen Comp 16George Acct 16Peter Phys 17Betty Math 16Cindy Eng 16Richard Acct 17Oliver Math 16

Page 26: 1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR,...... etc. The most.

26

The SAS System 09:51 Monday, November 8, 1999

OBS STUDNAM COURSE AGE

1 Albert Comp 17 2 May Acct 16 3 David Math 17 4 Helen Comp 16 5 George Acct 16 6 Peter Phys 17 7 Betty Math 16 8 Cindy Eng 16 9 Richard Acct 1710 Oliver Math 16

11111111112

12345678901234567890 Albert Comp 17

May Acct 16

David Math 17

Helen Comp 16

George Acct 16

Peter Phys 17

Betty Math 16

Cindy Eng 16

Richard Acct 17

Oliver Math 16

Page 27: 1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR,...... etc. The most.

27

Read Data From Dbase III FileWe do not have to inform our SAS system about the variable names. Our SAS program will use the field names from our data base file as the variable names. This program reads a DbaseIII file 'EMPLOYEE

Program Sample 5

The following program shows you how to read a Dbase III data file. The structure of our data file EMPLOYEE.DBF is as follows:

Field Name Type Width Dec

NAME Character 8

SEX Character 1

SALARY Numeric 5

Page 28: 1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR,...... etc. The most.

28

FILENAME DBFILE 'A:\EMPLOYEE.DBF'; PROC DBF DB3 = DBFILE OUT = A; RUN;

PROC PRINT DATA = A; RUN;

PROC SORT DATA = A OUT = B; BY NAME; RUN;

PROC PRINT DATA = B; VAR NAME SEX; RUN;

The SAS System 17:09 Friday, November 5, 1999

OBS NAME SEX SALARY

1 ALBERT M 2000 2 MARY F 2300 3 ANNA F 3000 4 STEVEN M 2300 5 GEORGE M 2000 6 ROSE F 2500 7 HELEN F 2450 8 CINDY F 2100 9 TONY M 260010 TOM M 231011 PETER M 220012 MONA F 321013 JAMES M 2190The SAS System 17:09

Friday, November 5, 1999

OBS NAME SEX

1 ALBERT M 2 ANNA F 3 CINDY F 4 GEORGE M 5 HELEN F 6 JAMES M 7 MARY F 8 MONA F 9 PETER M10 ROSE F11 STEVEN M12 TOM M13 TONY M

Page 29: 1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR,...... etc. The most.

29

Keyword Definition

RUN - Tells the SAS system to execute the previous SAS statements.

CARDS - Tells the SAS system that the data lines come next. You should enter one observation per data line. You must leave at least one blank between values.

DATA - Most collections of data are made up of many observations, each contains several variables.

PROC - ProcedureRECALL - Put the SAS statements back to Program Editor.BYE - Leave SAS systemENDSAS - Leave SAS systemFILE - Export data from active working window area e.g. File 'a:\abc.txt'INCLUDE - Import external data into active working window area

e.g. include 'a:\sa.SAS'CLEAR - Erase working window areaZOOM - Enlarge working window areaOPTIONS - Specify system options for the SAS sessions.

e.g. OPTIONS NODATE LS=132

Page 30: 1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR,...... etc. The most.

30

(a) Print Data Set (all)

PROC PRINT DATA = INCOME;RUN;

(b) Print Data Set (only the specified variables)

PROC PRINT DATA = INCOME;VAR NAME SEX;RUN;

(c) Print Data Set (with titles)

PROC PRINT DATA = INCOME;title1 'Employee Report';title2 'XYZ Company';RUN;

(d) Sort Data Set (by order of specified sort key)

PROC SORT DATA = INCOME OUT=SRTEMP;BY NAME;RUN;

Page 31: 1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR,...... etc. The most.

31

(e) PROC FREQ (Frequency Count)

PRO FREQ DATA = INCOME;TABLE NAME * SEX;RUN;

(f) PROC MEANS (Simple Statistics)

PROC MEANS DATA = INCOME;RUN;

(g) PROC GCHART (Simple Graphic Chart)

PROC GCHART DATA = INCOME;VBAR SALARY;RUN;

(h) PROC GCHART

PROC GCHART DATA = INCOME;PIE SALARY;RUN;

Page 32: 1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR,...... etc. The most.

32

That’s all