%let gpath='.';
%let dpi=200;
ods html close;
ods listing gpath=&gpath image_dpi=&dpi;
/*--Clean up data--*/
data heart;
set sashelp.heart(where=(deathcause ne ''));
keep deathcause cholesterol;
run;
/*--Scatter with Box--*/
ods graphics / reset width=5in height=3in imagename='Scatter_Box';
title 'Cholesterol by Death Cause';
proc sgplot data=heart nowall noborder noautolegend;
scatter x=deathcause y=cholesterol / jitter jitterwidth=0.5 transparency=0.9;
vbox cholesterol / category=deathcause nooutliers nomedian nomean nofill nocaps;
yaxis display=(noline noticks nolabel) grid;
xaxis display=(noline nolabel noticks);
run;
/*--Compute mean by death cause--*/
proc means data=heart noprint;
class deathcause;
var cholesterol;
output out=heart_mean(where=(_type_ > 0) rename=(deathcause=cause))
mean=mean;
run;
/*--Combine mean data with detailed data--*/
data combined;
merge heart heart_mean;
keep deathcause cholesterol cause mean;
run;
/*--Scatter with Mean--*/
ods graphics / reset width=5in height=3in imagename='Scatter_Mean';
title 'Cholesterol by Death Cause';
proc sgplot data=combined nowall noborder;
scatter x=deathcause y=cholesterol / jitter
jitterwidth=0.4 transparency=0.9;
highlow x=cause low=mean high=mean / type=bar
nofill lineattrs=(color=red)
barwidth=0.3 legendlabel='Mean';
yaxis display=(noline noticks nolabel) grid;
xaxis display=(noline nolabel noticks);
run;