/*Kaz's SAS juku course*/ /*www.estat.us*/ /*Kaz's SAS juku*/ /*www.estat.us*/ /*Descriptive Analysis*/ /*assigning nick names to directories*/ libname kaz_home "c:/temp/"; /*Reading a permanent data and creating a temporary data*/ data ABC; set sashelp.Class; ****************; *Creating a character variable indicating a person's BMI status (Body Mass Index); weight_metric=weight*0.45359237; height_metric=(height* 2.54)/100 ; BMI=weight_metric/(height_metric**2); /*Definition of obesity Normal weight = 18.5-24.9 Overweight = 25-29.9 Obesity = BMI of 30 or greater */ length status $ 15; If BMI < 18.5 then status="Underweight"; If BMI => 18.5 and BMI < 25 then status="Normal"; If BMI => 25 and BMI < 30 then status="Overweight"; If BMI >= 30 then status="Obese"; ****************; run; /*descriptive statistics and simple univariate plot*/ proc univariate data=ABC plot; var age height weight; run; /*Look at the data by eyeball*/ proc sort data=ABC out=ABC;by height;run; proc timeplot data=ABC; title "Time plot for HEIGHT"; plot height / overlay ref=mean(height ) hiloc npp; id NAME sex status; run; /*simple correlation among continous scales*/ proc corr data=ABC; title "Correlation"; var age height weight; run; /*plot of two continuous scales*/ proc plot data=ABC; title "Plot"; plot height*weight ;run; run; /*comparison of subgroup means*/ proc means data=ABC; title "Subgroup Mean"; class sex; var height weight; run; /*creating box plots*/ proc sort data=ABC out=ABC;by sex;run; proc univariate data=ABC plot; title "box plots"; by sex; var height weight; run; /*Association among categorical variables*/ proc freq data=ABC; title "frequencies"; tables sex*status; run; /*Analysis of variance using GLM*/ proc glm data=ABC; title "GLM"; class sex; model weight=sex/solution e /*noint*/; lsmeans sex/ stderr cov tdiff; run; /*I don't know why but proc GLM seems not stopping after the run by itself, so I say "quit" here*/ quit; /*Any of above procedures' results can be saved as SAS data sets, so they can be then manipulated to look good when printed or saved as excel data*/ /*To do that: a) suppressing printing of default outputs by saying ODS listneing close at the beginning and ODS listing at the end. b) ODS output statement list many table names, such as OverallANOVA or FitStatistics. To learn what tables are available, do ods trace on in the beginning of a procedure and look at SAS log. To stop "tracing," do "ods trace off." For example: ods trace on; proc contents; run; ods trace off; And see the log file to learn the names of the tables that PROC CONTENTS produce. */ /*proc glm using ODS to save results as data sets, while suppressing the default printing*/ ODS listing close; proc glm data=ABC; class sex; model weight=sex/solution e /*noint*/; lsmeans sex/ stderr cov tdiff; means sex/ tukey alpha=.05 ; ods output OverallANOVA=info1 FitStatistics=info2 parameterestimates=info3 ModelANOVA=info4; run; ODS listing; proc print data=info1;run; proc print data=info2;run; proc print data=info3;run; proc print data=info4;run;