A Gentle Introduction to Using SAS (Part II) Statistics 101

7 downloads 150 Views 15KB Size Report
In this second installment of our introduction to SAS, we will demonstrate how to ... PROGRAM EDITOR, LOG and OUTPUT windows) is opened automatically.
A Gentle Introduction to Using SAS (Part II)1 Statistics 101 Spring 1999

In this second installment of our introduction to SAS, we will demonstrate how to produce bar charts in SAS. It is assumed that you have successfully completed all the tasks prescribed in the previous installments. PRELIMINARY NOTE: 1. Whenever graphics are produced in SAS, a GRAPH window (in addition to the PROGRAM EDITOR, LOG and OUTPUT windows) is opened automatically. To organize the windows choose [Tile] from the [Windows] menu. 2. Whenever a graph is produced, it is appended to end of the existing list of graphs. The user can easily browse through this collection by using the Page Up and Page Down buttons on the keyboard.

3. To print out a graph, that graph must appear in the GRAPH window.

DATA SET: For this demonstration we will use the following data set. The columns represent the names, weights (in pounds), heights (in inches) and gender for twelve fictitious individuals. Joe Tim Moe Jim Al Ty Jill Ruth Anna Kate Mary Ada

1

180 225 300 184 190 142 125 110 119 127 140 100

72 68 70 79 61 67 51 60 59 55 70 53

M M M M M M F F F F F F

Please direct any comments or suggestion to Kouros Owzar ([email protected]).

1

OBJECTIVE: Our objective is to write a SAS code that carries out following tasks: 1. Reads in the data from this file and store it to a data set called test. 2. Prints out all four columns (i.e., name, weight, height and gender). 3. [Graph #1] Produces vertical bar charts for the height variable. 4. [Graph #2] Produces a horizontal bar chart for the weight variable. 5. [Graph #3] Produces a horizontal bar chart for the weight variable with midpoints at 180 and 200. 6. [Graph #4] Produces a vertical frequency bar chart that displays the mean weight for each gender. 7. Produces a horizontal percentage bar chart for the weight variable (graph #5).

2

SAMPLE SAS CODE: DATA test; INFILE 'a:\try.dat'; INPUT name $ weight height gender $; RUN;QUIT; PROC PRINT DATA=test; RUN;QUIT; TITLE 'GRAPH #1'; PROC GCHART DATA=test; VBAR height; RUN;QUIT; TITLE 'GRAPH #2'; PROC GCHART DATA=test; HBAR weight; RUN;QUIT; TITLE 'GRAPH #3'; PROC GCHART DATA=test; HBAR weight / MIDPOINTS=(180,200); RUN;QUIT; PROC SORT DATA=test; BY gender weight; RUN;QUIT; TITLE 'GRAPH #4'; PROC GCHART DATA=test; VBAR gender / TYPE=MEAN SUMVAR=weight; RUN;QUIT; TITLE 'GRAPH #5'; PROC GCHART DATA=test; HBAR weight / TYPE=PERCENT; RUN;QUIT;

3

THE MAIN TASKS:

1. Start up a SAS session by clicking on the SAS icon. 2. Download the file try.dat from the course web-site2 onto your floppy disk (see lab assistant if you do not know how to do this). 3. Type in above SAS code in to the PROGRAM EDITOR window. 4. While PROGRAM EDITOR is active, choose [Save] from the [File] menu to save the program on your floppy disk as try2.sas. 5. While PROGRAM EDITOR is active, choose [Submit] from the [Locals] menu to execute the program. 6. Look in the LOG window for any errors or warnings, which would appear in red and green colored fonts respectively. 7. If there are any warnings, compare the code which you have typed in for any discrepancies with the code given above. 8. Look in the OUTPUT window to verify that the data set was read in successfully. 9. Activate the GRAPH window. 10. Scroll up and down the list of graphs by using the Page up and Page Down keys. 11. Print out the two graphs of your choice (make sure that the graph appears in the GRAPH window).

2

http://www.stat.unc.edu/students/owzar/stat101.html

4