/* CholesterolExample.sas */ /* ---------------------------------------------------------*/ /* ------ Guatemalan cholesterol example -------------------*/ /* ---------------------------------------------------------*/ /* ---------------------------------------------------------*/ data cholest1; input level group $; cards; 95 rural 108 rural 108 rural 114 rural 115 rural 124 rural 129 rural 129 rural 131 rural 131 rural 135 rural 136 rural 136 rural 139 rural 140 rural 142 rural 142 rural 143 rural 143 rural 144 rural 144 rural 145 rural 146 rural 148 rural 152 rural 152 rural 155 rural 157 rural 158 rural 158 rural 162 rural 165 rural 166 rural 171 rural 172 rural 173 rural 174 rural 175 rural 180 rural 181 rural 189 rural 192 rural 194 rural 197 rural 204 rural 220 rural 223 rural 226 rural 231 rural 133 urban 134 urban 155 urban 170 urban 175 urban 179 urban 181 urban 184 urban 188 urban 189 urban 190 urban 196 urban 197 urban 199 urban 200 urban 200 urban 201 urban 201 urban 204 urban 205 urban 205 urban 205 urban 206 urban 214 urban 217 urban 222 urban 222 urban 227 urban 227 urban 228 urban 234 urban 234 urban 236 urban 239 urban 241 urban 242 urban 244 urban 249 urban 252 urban 273 urban 279 urban 284 urban 284 urban 284 urban 330 urban ; /* -------------------------------------------------------- */ /* ---------------------------------------------------------*/ /* Guatemalan cholesterol level distribution all observations */ /* ---------------------------------------------------------*/ proc univariate data=cholest1 nextrval=5; class group; var level; ods select ExtremeValues BasicMeasures Quantiles; title 'Guatemalan cholesterol example summary'; /* class group; indicates that the data are to be divided into classes corresponding to the levels of the classification variable -- group in this example NOTE: the data do not need to be sorted with the class statement */ proc means data=cholest1 maxdec=2 n min q1 median q3 max range qrange mean std; class group; var level; proc means data=cholest1 maxdec=2 p1 p5 p10 p20 p30 p40 p50 p60 p70 p80 p90 p95 p99; class group; var level; /* ---------------------------------------------------------*/ /* some graphics */ /* cholesterol level distribution by group -- histogram and smoothed histogram */ /* -------------------------------------------------------- */ proc sgpanel data=cholest1 pctlevel=group; title 'Guatemalan cholesterol example'; panelby group; histogram level / binstart=100 binwidth=20 datalabel=percent; density level / type=kernel; run; title; /* title assigns a title for the output -- panelby group; requests a graph for each group --histogram options-- datalabel=percent: display percentage at end of bin use datalabel=count to get frequency --density options-- type=kernel requests a fitted smooth density */ /* -------------------------------------------------------- */ /* cholesterol level distribution by group -- histogram, smoothed histogram, and fitted normal distribution */ /* -------------------------------------------------------- */ proc sgpanel data=cholest1 pctlevel=group; title 'Guatemalan cholesterol example'; panelby group; histogram level / binstart=100 binwidth=20; density level / type=normal; density level / type=kernel; /* type=normal requests a fitted normal density type=kernel requests a fitted smooth density */ run; title; /* -------------------------------------------------------- */ /* cholesterol level distribution by group -- box plots */ /* -------------------------------------------------------- */ proc sgplot data=cholest1; hbox level / group=group; title 'cholest level dist box plots'; run; title; /* -------------------------------------------------------- */ /* -------------------------------------------------------- */ proc sgplot data=cholest1; title 'Guatemalan cholesterol level dist (overlaid plots)'; histogram level / binstart=100 binwidth=20 transparency=0.4 datalabel=percent group=group; density level / type=normal group=group; density level / type=kernel group=group; run; title; title2; /* -------------------------------------------------------- */ /* -------------------------------------------------------- */ /* -------------------------------------------------------- */ /* ---------------------------------------------------------*/ /* Guatemalan cholesterol level distribution omitting the urban outlier (330) */ /* ---------------------------------------------------------*/ data cholest2; set cholest1; if level=330 then delete; proc univariate data=cholest2 nextrval=5; class group; var level; ods select ExtremeValues BasicMeasures Quantiles; title 'Guatemalan cholesterol example summary without the outlier'; proc means data=cholest2 maxdec=2 n min q1 median q3 max range qrange mean std; class group; var level; proc means data=cholest2 maxdec=2 p1 p5 p10 p20 p30 p40 p50 p60 p70 p80 p90 p95 p99; class group; var level; run; title; proc sgplot data=cholest2; title 'Guatemalan cholesterol level dist (overlaid plots) without the outlier'; histogram level / binstart=100 binwidth=20 transparency=0.4 datalabel=percent group=group; density level / type=normal group=group; density level / type=kernel group=group; run; title; title2;