1 / 32

SAS

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

licia
Télécharger la présentation

SAS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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

  2. Structure A 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.

  3. SAS Statement Every 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;

  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

  5. data income; • infile 'c:\income.dat'; • input name$ sex$ salary; • run; • data income; • input name$ sex$ salary; • cards; • George M 2300 • Amy F 2500 • Steve M 2200 • Tom M 4400 • ; • run;

  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.

  7. input name$ 1-8 • sex$ 9-9 • salary; • input name$ sex$ salary;

  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.

  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

  10. 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;

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

  12. 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 21 mary f 3000 18 helen f 3000 20 jack m 4500 22 tony m 4500 19 anna f 3000 21 willie m 4500 18 ; proc print data = income; var n sex; run; proc freq data = income; table sex * salary; run;

  13. 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 21 mary f 3000 18 helen f 3000 20 jack m 4500 22 tony m 4500 19 anna f 3000 21 willie m 4500 18 ; proc print data = income; var n sex; run; proc freq data = income; table sex * salary; run;

  14. 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 21 mary f 3000 18 helen f 3000 20 jack m 4500 22 tony m 4500 19 anna f 3000 21 willie m 4500 18 ; proc print data = income; var n sex salary age; run;

  15. options nodate; title1 'XYZ Company'; title2 'Salary Report'; data income; input n$ sex$ salary age; if sex = 'm' then delete; cards; john m 3000 21 mary f 3000 18 helen f 3000 20 jack m 4500 22 tony m 4500 19 anna f 3000 21 willie m 4500 18 ; proc print data = income; var n sex salary age; run; XYZ Company Salary Report OBS N SEX SALARY AGE 1 mary f 3000 18 2 helen f 3000 20 3 anna f 3000 21

  16. Program Sample 4 The 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 10 Course - column 11 to column 14 Age - column 18 to column 19 * column 15 to column 17 ignored 1111111112 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

  17. data student; infile 'a:\student.dat'; input studnam $ 1-10 course $ 11-14 age 18-19; run; proc print data = student; run; 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

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

  19. Read Data From Dbase III File We 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

  20. 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 2600 10 TOM M 2310 11 PETER M 2200 12 MONA F 3210 13 JAMES M 2190 The 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 M 10 ROSE F 11 STEVEN M 12 TOM M 13 TONY M

  21. 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 - Procedure RECALL - Put the SAS statements back to Program Editor. BYE - Leave SAS system ENDSAS - Leave SAS system FILE - 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 area ZOOM - Enlarge working window area OPTIONS - Specify system options for the SAS sessions. e.g. OPTIONS NODATE LS=132

  22. (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;

  23. (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;

  24. That’s all

More Related