%let gpath='C:\';
%let dpi=100;
ods html close;
ods listing gpath=&gpath image_dpi=&dpi;
proc format;
value trt
1='A'
2='B'
3='C'
other=' ';
run;
/*--Original data--*/
data try;
input trt numb value mean median run;
format trt trt.;
cards;
1 101 26.5 33.9 27.8 7
1 102 29 33.9 27.8 7
1 103 49.1 33.9 27.8 7
1 104 26 33.9 27.8 7
1 105 52.8 33.9 27.8 7
1 106 19.9 33.9 27.8 7
2 201 25.8 30.4 28.3 8
2 202 16.7 30.4 28.3 8
2 203 38.1 30.4 28.3 8
2 204 30.7 30.4 28.3 8
2 205 51.3 30.4 28.3 8
2 206 19.8 30.4 28.3 8
3 301 26.5 33.9 27.8 9
3 302 29 33.9 27.8 9
3 303 49.1 33.9 27.8 9
3 304 26 33.9 27.8 9
3 305 52.8 33.9 27.8 9
3 306 19.9 33.9 27.8 9
;
run;
/*--Load statistics into macro variables--*/
data Stat;
set try end=last;
by trt;
if last.trt then do;
if trt eq 1 then do;
call symput ("Mean1", mean);
call symput ("Median1", median);
end;
else if trt eq 2 then do;
call symput ("Mean2", mean);
call symput ("Median2", median);
end;
else do;
call symput ("Mean3", mean);
call symput ("Median3", median);
end;
end;
run;
/*--Basic scatter plot--*/
ods graphics / reset width=4in height=2.5in imagename='Scatter';
title 'Value by Treatment with Statistics';
proc sgplot data=Stat noautolegend;
scatter x = trt y = value / markerattrs=(size=9 symbol=circle color=black);
inset ("Mean A"="= &mean1" "Mean B"="= &mean2" "Mean C"="= &mean3"
"Median A"="= &median1" "Median B"="= &median2" "Median C"="= &median3"
) / position=bottomright border;
xaxis min=0.5 max=3.5 values=(1 to 3 by 1) label='Trt' offsetmax=0.4;
yaxis values=(-10 to 60 by 10) label="Value" ;
run;
/*--Create data set with embedded stat values--*/
data table;
set try end=last;
by trt;
if last.trt then do;
output;
stat="Median"; sval=median; output;
stat="Mean"; sval=mean; output;
end;
else output;
run;
proc print; run;
/*--Scatter with axis aligned table--*/
ods graphics / reset width=4in height=2.5in imagename='ScatterTable';
title 'Value by Treatment with Statistics';
proc sgplot data=table noautolegend;
scatter x = trt y = value / markerattrs=(size=9 symbol=circle color=black);
scatter x=trt y=stat / markerchar=sval y2axis;
xaxis min=0.5 max=3.5 values=(1 to 3 by 1) label='Trt';
yaxis values=(-10 to 60 by 10) label="Value" offsetmin=0.15;
y2axis offsetmax=0.89 display=(nolabel);
run;
/*--Create data set with embedded stat values and character strings--*/
data MarkerChars;
set try end=last;
by trt;
if last.trt then do;
output;
stat=mean; bar='- - - - - -'; output;
stat=median; bar='---------'; output;
end;
else output;
run;
/*--Display derived stats using MarkerChar--*/
ods graphics / reset width=4in height=2.5in imagename='InsetMarkerChar';
title 'Value by Treatment with Statistics';
proc sgplot data=MarkerChars noautolegend;
scatter x = trt y = value / markerattrs=(size=9 symbol=circle color=black);
scatter x = trt y = stat / MARKERCHAR=bar;
inset ( "- - - - -"="Mean" "--------" = "Median") / position=bottomright border;
xaxis values=(1 to 3 by 1) label='Trt' ;
yaxis values=(-10 to 60 by 10) label="Value" ;
run;
/*--Create data set with embedded stat values and vector plot values--*/
data Vector;
length stat $6;
set try end=last;
by trt;
if last.trt then do;
output;
x1=trt-0.25; x2=trt+0.25;
y=mean; stat="Mean"; output;
y=median; stat="Median"; output;
end;
else output;
run;
/*--Create a style with custom patterns--*/
%modstyle(name=pattern, parent=listing, type=CLM,
linestyles=solid shortdash);
/*--Display derived stats using Vector Plot--*/
ods listing style=pattern;
ods graphics / reset width=4in height=2.5in imagename='InsetVector';
title 'Value by Treatment with Statistics';
proc sgplot data=Vector noautolegend nocycleattrs;
scatter x = trt y = value / markerattrs=(size=9 symbol=circle color=black);
vector x=x2 y=y / xorigin=x1 yorigin=y group=stat noarrowheads
nomissinggroup lineattrs=(thickness=2) name='v';
keylegend 'v' / location=inside position=bottomright;
xaxis min=0.5 max=3.5 values=(1 to 3 by 1) valueshint label='Trt' ;
yaxis values=(-10 to 60 by 10) label="Value";
run;