So,
I've decided to go with SGPANEL and have given up on SGPLOT and got the following code going:
data have;
set sashelp.heart(obs=1000);
run;
%macro box_plot(dsn=,x=,y=,title=);
ods select none;
ods output sgpanel=sgplot2;
proc sgpanel data=&dsn.;
panelby bp_status;
vbox &y./ category=&x. ;
run;
ods select all;
%let dsid=%sysfunc(open(sgplot2));
%let first=%sysfunc(nliteral(%sysfunc(varname(&dsid,1))));
%let second=%sysfunc(nliteral(%sysfunc(varname(&dsid,2))));
%let third=%sysfunc(nliteral(%sysfunc(varname(&dsid,3))));
%let dsid=%sysfunc(close(&dsid));
data temp(rename=(&third.=&x. &first.=_y &second.=_stat));
set sgplot2;
_value=round(&first.,0.01);
if not missing(&second.) and &second. in ('MIN' 'MAX' 'MEDIAN' 'MEAN' 'Q1' 'Q3');
keep _value &first. &second. &third. bp_status;
run;
data want;
set &dsn. temp;
if _stat in ( 'MEDIAN') then _value1=_value;
if _stat in ( 'MIN') then _value2=_value;
if _stat in ('MAX') then _value3=_value;
if _stat in ( 'MEAN' ) then _value4=_value;
run;
title c=black "&title.";
proc sgpanel data=want noautolegend ;
panelby bp_status;
vbox &y./category=&x. nomean boxwidth=0.2;
scatter x=&x. y=_y / discreteoffset=0.2 markerchar=_value1 labelstrip markercharattrs=(size=8);
scatter x=&x. y=_y /discreteoffset=0.2 markerchar=_value2 labelstrip markercharattrs=(size=8);
scatter x=&x. y=_y /discreteoffset=0.2 markerchar=_value3 labelstrip markercharattrs=(size=8);
scatter x=&x. y=_y /discreteoffset=0.2 markerchar=_value4 labelstrip markercharattrs=(size=8);
scatter x=&x. y=_value4 /markerattrs=(color=darkred symbol=circlefilled) name='mean' legendlabel='Mean' ;
scatter x=&x. y=_value1 /markerattrs=(color=navy symbol=diamondfilled) name='median' legendlabel='Median' ;
keylegend 'mean' 'median'/AUTOITEMSIZE;
run;
title;
%mend;
%box_plot(dsn=have, x=sex, y=weight, title=VCSS-Score)
I greatly dislike the way the panel's output in this one as it's hard to tell what the scale is all the time:
I would like everything in one panel but what can I do??
Thank you,
J Fuchsia
... View more