dm "log; clear; odsresults; clear;"; options linesize=64 nonumber nodate; *********************************************************************; * AUTHOR: Chris Bilder *; * DATE: 4-27-16 *; * PURPOSE: Summary parts of the cereal data set *; *********************************************************************; *Will appear as the first line of every page of output; title1 "Chris Bilder, STAT 850"; *Read in the data set from a comma delimited file; proc import out=cereal datafile="C:\data\cereal.csv" DBMS=CSV replace; getnames=yes; datarow=2; run; *Adjust for serving size; data set1; set cereal; sugar = sugar_g/size_g; fat = fat_g/size_g; sodium = sodium_mg/size_g; *remove the old variables below from the data set; drop size_g sugar_g fat_g sodium_mg; run; title2 "Cereal data adjusted for serving size"; proc print data=set1(obs = 5); run; *********************************************************************; * Proc means examples; title2 "Means for cereal data"; proc means data=set1; var sugar fat sodium; output out=out_set1; run; title2 "Out data set from proc means"; proc print data=out_set1; run; title2 "Means for cereal data for shelf class"; proc means data=set1; class shelf; var sugar fat sodium; run; title2 "Means for cereal data by shelf"; proc means data=set1; var sugar fat sodium; by shelf; run; title2 "Show how to use options in proc means"; proc means data=set1 mean alpha=0.05 clm median p50 std; class shelf; var sugar fat sodium; output out=out_set1; run; title2 "Out data set from proc means"; proc print data=out_set1; run; *Showing how to work with options in output statement; *Only information for sugar is given in the output data set; proc means data=set1 mean alpha=0.05 clm median p50 std noprint; class shelf; var sugar fat sodium; output out=out_set2 mean=mean LCLM=lower UCLM=upper; output out=out_set3 mean(sodium) = mean LCLM = lower UCLM = upper; output out=out_set4 mean(sugar) = mean1 mean(sodium) = mean2 LCLM = lower UCLM = upper; output out=out_set5 mean=mean LCLM=lower UCLM=upper / autoname; run; *********************************************************************; * ODS; ods trace on; *Print ODS table names in log window; title2 "Means for cereal data"; proc means data=set1 mean; var sugar fat sodium; run; ods trace off; *ODS names are no longer printed; *A table named summary is available so the code is re-run with a * ods output statement; title2 "Means for cereal data"; proc means data=set1 mean; var sugar fat sodium; ods output summary=ods_set1; run; title2 "ODS generated table"; proc print data=ods_set1; run; **********************************************************************; * Example of how to skip over code with /* */ *********************************************************************; * Proc means examples; title2 "Means for cereal data"; proc means data=set1; var sugar fat sodium; output out=out_set1; run; /* This code is not run title2 "Out data set from proc means"; proc print data=out_set1; run; title2 "Means for cereal data for shelf class"; proc means data=set1; class shelf; var sugar fat sodium; run; */ title2 "Means for cereal data by shelf"; proc means data=set1; var sugar fat sodium; by shelf; run;