Week 3 Topic - Descriptive Procedures Program 3 in course notes Cody & Smith (Chapter 2)
Steps in Creating and Running a SAS Program 1.Create or edit SAS program > pico fn.sas (cntr x to exit) 2.Run the SAS program > sas fn.sas 3.List the files in directory - look for.log and.lst files > ls 4.View the.log file - look for errors and notes > less fn.log (type q to exit) 5.If errors go back to step 1 and repeat When no errors view.lst to view output > less fn.lst
Data Layout of tomhs.data Page of Course Notes VariableTypeLenPosInformDescription PTIDChar101$10.Patient ID RANDDATENum614mmddyy6.Rand. date SBPBLNum3733.SBP at baseline DATA tomhs; INFILE '/home/ph5420/data/tomhs.data'; ptid randdate sbpbl 3. ;
SAS Descriptive Procedures PROC PRINT PROC MEANS PROC UNIVARIATE PROC FREQ PROC PLOT PROC CHART
Syntax for Procedures PROC PROCNAME DATA=datasetname ; substatements/ ;
* PROGRAM 3; DATA weight; INFORMAT patid $10. ; INFILE '/home/ph5420/data/htwt.data' ; INPUT patid $ clinic $ sex $ height weight ; bmi = (weight* )/(height*height); RUN; C03615AANE C B00025PAYN B B00979YOUN B …
PROC PRINT DATA = weight (OBS=5) NOOBS; TITLE 'Proc Print: Five observations from the TOMHS Study'; RUN; PROC MEANS DATA = weight; VAR height weight bmi; TITLE 'Proc Means Example 1'; RUN; PROC MEANS DATA = weight MEAN MEDIAN STD MAXDEC=2; TITLE 'Proc Means Example 2 (specifying options)'; RUN; Page 25 of Cody/Smith lists statistics available Note: Median available in Version 8 of SAS
Proc Print: Five observations from the TOMHS Study patid clinic sex height weight bmi C03615AANE C B00979YOUN B B00644MATS B D01348HART D A01088COLL A Proc Means Example 1 The MEANS Procedure Variable N Mean Std Dev Minimum Maximum height weight bmi
Proc Means Example 2 (specifying options) The MEANS Procedure Variable Mean Median Std Dev height weight bmi
PROC MEANS DATA = weight N MEAN STD MAXDEC=2; CLASS clinic; TITLE 'Proc Means Example 3 (Using a CLASS statement)'; RUN; PROC MEANS DATA = weight N MEAN STD MAXDEC=2; CLASS clinic; WAYS 0 1 ; TITLE 'Proc Means Example 4 (Using WAYS statement)'; RUN;
Proc Means Example 3 (Using a CLASS statement) The MEANS Procedure N clinic Obs Variable N Mean Std Dev A 18 height weight bmi B 29 height weight bmi C 36 height weight bmi D 17 height weight bmi
Proc Means Example 4 (Using WAYS statement) The MEANS Procedure N Obs Variable N Mean Std Dev height weight bmi N clinic Obs Variable N Mean Std Dev A 18 height weight bmi B 29 height weight bmi C 36 height weight bmi D 17 height weight bmi
PROC UNIVARIATE DATA = weight PLOT ; ID patid; VAR bmi; TITLE 'Proc Univariate Example 1'; RUN; * Note: PROC UNIVARIATE will give you much output ;
Proc Univariate Example 1 The UNIVARIATE Procedure Variable: bmi Moments N 100 Sum Weights 100 Mean Sum Observations Std Deviation Variance Skewness Kurtosis Uncorrected SS Corrected SS Coeff Variation Std Error Mean Basic Statistical Measures Location Variability Mean Std Deviation Median Variance Mode Range Interquartile Range Tests for Location: Mu0=0 Test -Statistic p Value Student's t t Pr > |t| <.0001 Sign M 50 Pr >= |M| <.0001 Signed Rank S 2525 Pr >= |S| <.0001
Quantile Estimate 100% Max % % % % Q % Median % Q % % % % Min Extreme Observations Lowest Highest Value patid Obs Value patid Obs A00083ROBE B00979YOUN C04206ETLI B03077ANDE B00714OBRI A01166MCAN A00312HAYN C05323OLSO B00262JONE B02059MCHA 25
Stem Leaf # Boxplot | | | | | | | | | | + | *-----* | | | | | | | | th Percentile 25th Percentile Mean
The UNIVARIATE Procedure Variable: bmi Normal Probability Plot * *+ * | *++ | *** | ***+ | ***** | **+++ | **++ | * ** | ++*** | +**** | **** | ***+ | * *** *
* High resolution graphs can also be produced. The following makes a pdf file containing a histogram ; GOPTIONS DEVICE=pdfc GSFNAME=bmiplot FTEXT=swissb ROTATE GSFMODE=replace HTITLE=3 HTEXT=1.5; FILENAME bmiplot 'bmiplot.pdf'; PROC UNIVARIATE DATA = weight; VAR bmi; HISTOGRAM bmi / NORMAL MIDPOINTS=20 to 40 by 2; INSET N = 'N' (5.0) MEAN = 'Mean' (5.1) STD = 'Sdev' (5.1) MIN = 'Min' (5.1) MAX = 'Max' (5.1)/ POS=lm HEADER='Summary Statistics'; LABEL bmi = 'Body Mass Index (kg/m2)'; TITLE 'Histogram of BMI'; RUN;
Using Comment Statements in SAS Two Purposes 1.Documenting your program 2.Temporary deleting part of a program
Examples of Comment Code * Run proc univariate for variable BMI; PROC UNIVARIATE DATA = weight PLOT ; * ID patid ; VAR bmi; PROC UNIVARIATE DATA = weight /*PLOT*/; VAR bmi;