Hi Team,
I'm trying to create BOXPLOT, as per below mock, using styles.rtf.
But I'm getting output as below.
I'm unable to restrict FILLPATTERN and unable to get DASHED lines for entire box.
Also, I'm restricted to use STYLE.RTF only.
I'm using below TEMPLATE code for creating BOXPLOT.
Please can you help in fixing the above issue.
Regards,
Anvesh
Your question is really not easy.
Here is an example.
Hope you can get the graph you want by refer to the following code.
Good Luck.
[Edited]
data have;
set sashelp.heart(keep=status sex weight);
run;
ods select none;
ods output sgplot=sgplot;
proc sgplot data=have;
vbox weight/category=status group=sex nooutliers ;
run;
ods select all;
data want;
set sgplot;
if BOX_WEIGHT_X_STATUS_GROUP_SE__ST in ('MIN' 'Q1' 'MEDIAN' 'Q3' 'MAX' 'MEAN') ;
run;
proc sort data=want;by BOX_WEIGHT_X_STATUS_GROUP_SE___X BOX_WEIGHT_X_STATUS_GROUP_SE__GP;run;
proc transpose data=want out=want2;
by BOX_WEIGHT_X_STATUS_GROUP_SE___X BOX_WEIGHT_X_STATUS_GROUP_SE__GP;
var BOX_WEIGHT_X_STATUS_GROUP_SE___Y;
id BOX_WEIGHT_X_STATUS_GROUP_SE__ST;
run;
data want2;
set want2;
l_mean=mean-5;
h_mean=mean+5;
run;
ods graphics/ATTRPRIORITY=none;
proc sgplot data=want2;
styleattrs DATALINEPATTERNS=(solid shortdash) ;
highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=max low=min /
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster;
highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=q3 low=q1/type=bar barwidth=0.5 nooutline
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster fillattrs=(color=white);
highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=q3 low=q1/type=bar barwidth=0.5
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster nofill;
highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=median low=median/type=bar barwidth=0.5
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster nofill;
highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=min low=min/type=bar barwidth=0.5
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster nofill;
highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=max low=max/type=bar barwidth=0.5
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster nofill;
highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=mean low=mean/type=bar barwidth=0.2
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster nofill;
highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=h_mean low=l_mean/
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster ;
run;
Try to remove "fillpattern" from the display= option, and add "pattern=3" into outlineattrs=, whiskerattrs= and medianattrs= options.
Your question is really not easy.
Here is an example.
Hope you can get the graph you want by refer to the following code.
Good Luck.
[Edited]
data have;
set sashelp.heart(keep=status sex weight);
run;
ods select none;
ods output sgplot=sgplot;
proc sgplot data=have;
vbox weight/category=status group=sex nooutliers ;
run;
ods select all;
data want;
set sgplot;
if BOX_WEIGHT_X_STATUS_GROUP_SE__ST in ('MIN' 'Q1' 'MEDIAN' 'Q3' 'MAX' 'MEAN') ;
run;
proc sort data=want;by BOX_WEIGHT_X_STATUS_GROUP_SE___X BOX_WEIGHT_X_STATUS_GROUP_SE__GP;run;
proc transpose data=want out=want2;
by BOX_WEIGHT_X_STATUS_GROUP_SE___X BOX_WEIGHT_X_STATUS_GROUP_SE__GP;
var BOX_WEIGHT_X_STATUS_GROUP_SE___Y;
id BOX_WEIGHT_X_STATUS_GROUP_SE__ST;
run;
data want2;
set want2;
l_mean=mean-5;
h_mean=mean+5;
run;
ods graphics/ATTRPRIORITY=none;
proc sgplot data=want2;
styleattrs DATALINEPATTERNS=(solid shortdash) ;
highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=max low=min /
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster;
highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=q3 low=q1/type=bar barwidth=0.5 nooutline
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster fillattrs=(color=white);
highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=q3 low=q1/type=bar barwidth=0.5
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster nofill;
highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=median low=median/type=bar barwidth=0.5
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster nofill;
highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=min low=min/type=bar barwidth=0.5
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster nofill;
highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=max low=max/type=bar barwidth=0.5
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster nofill;
highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=mean low=mean/type=bar barwidth=0.2
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster nofill;
highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=h_mean low=l_mean/
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster ;
run;
Hi Ksharp,
Thanks you a lot. The solution you shared suffice the mock requirements. But it is not producing all the stats (MIN, MAX, MEAN, MEDIAN, N, DATAMAX, DATAMIN, OUTLIERS etc) produced by BOXPLOT in graph output.
Hi Ksharp,
Please find the screenshot of the output I needed, as requested.
So what is different between yours and mine?
The max min value in my graph is not real max min of value.
Check the following picture to see what box line stand for.
Thank You Ksharp.
We are getting all stats, except outliers. However, I hope in this model (solid and dashed), we cannot get outliers differentiated.
Your response suffice mock requirements, as shown in figure.
Thanks a lot.
OK. You want outliers as SAS did ? No problem.
data have;
set sashelp.heart(keep=status sex weight);
run;
ods select none;
ods output sgplot=sgplot;
proc sgplot data=have;
vbox weight/category=status group=sex ;
run;
ods select all;
data stat outliers;
set sgplot;
if BOX_WEIGHT_X_STATUS_GROUP_SE__ST in ('MIN' 'Q1' 'MEDIAN' 'Q3' 'MAX' 'MEAN') then output stat;
if find(BOX_WEIGHT_X_STATUS_GROUP_SE__ST,'OUTLIER') then output outliers;
run;
proc sort data=stat;by BOX_WEIGHT_X_STATUS_GROUP_SE___X BOX_WEIGHT_X_STATUS_GROUP_SE__GP;run;
proc transpose data=stat out=stat2;
by BOX_WEIGHT_X_STATUS_GROUP_SE___X BOX_WEIGHT_X_STATUS_GROUP_SE__GP;
var BOX_WEIGHT_X_STATUS_GROUP_SE___Y;
id BOX_WEIGHT_X_STATUS_GROUP_SE__ST;
run;
data stat2;
set stat2;
l_mean=mean-5;
h_mean=mean+5;
run;
data want;
set stat2 outliers;
run;
ods graphics/ATTRPRIORITY=none;
proc sgplot data=want;
styleattrs DATALINEPATTERNS=(solid shortdash) ;
highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=max low=min /
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster;
highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=q3 low=q1/type=bar barwidth=0.5 nooutline
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster fillattrs=(color=white);
highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=q3 low=q1/type=bar barwidth=0.5
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster nofill;
highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=median low=median/type=bar barwidth=0.5
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster nofill;
highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=min low=min/type=bar barwidth=0.3
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster nofill;
highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=max low=max/type=bar barwidth=0.3
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster nofill;
highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=mean low=mean/type=bar barwidth=0.15
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster nofill;
highlow x=BOX_WEIGHT_X_STATUS_GROUP_SE___X high=h_mean low=l_mean/
lineattrs=(color=black) group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster ;
scatter x=BOX_WEIGHT_X_STATUS_GROUP_SE___X y=BOX_WEIGHT_X_STATUS_GROUP_SE___Y/
group=BOX_WEIGHT_X_STATUS_GROUP_SE__GP groupdisplay=cluster markerattrs=(color=black);
run;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.