%let gpath='.'; ods html close; %let dpi=200; ods listing gpath=&gpath image_dpi=&dpi; /*--Compute mean by sex--*/ proc means data=sashelp.class; class sex; var height; output out=class_mean(where=(_type_ ne 0)) mean=meanHeight; run; /*--Merge mean values with original data set--*/ data class; format meanHeight 4.1; set sashelp.class(keep=height weight sex) class_mean(keep=sex meanHeight); if meanHeight then do; lbl=cat("Mean=", put (meanheight, 4.1)); zero=0; end; run; /*ods html;*/ /*proc print;run;*/ /*ods html close;*/ /*--Sort data by sex for ByVar processing--*/ proc sort data=class out=class2; by sex; run; /*--Render scatter plot with overlay of RefLine and Text plot--*/ ods graphics / reset width=4in height=3in imagename='HeightBySex'; title 'Height by Weight'; proc sgplot data=class2 uniform=yscale noautolegend; by sex; scatter x=weight y=height; refline meanHeight; text x=zero y=meanHeight text=lbl / position=topright; run;