Hi all,
I am having difficulties adding summary statistics to a box plot in the PROC SGPANEL procedure (ONLY when there is a group variable in the VBOX statement).
Example:
PROC SGPANEL DATA=lvmi;
PANELBY yearsincetx_grp / ROWS=1;
WHERE yearsincetx_grp=1 or yearsincetx_grp=2 or yearsincetx_grp=3;
VBOX lvmi / CATEGORY=im53 displaystats=(N mean); *CSA;
ROWAXIS values= (20 to 120 by 10);
TITLE 'lvmi vs CSA by year';
RUN;
This code runs perfectly fine and produces the mean and N observation for each group on the x axis.
However, when I add sex as a grouping variable, it no longer works. I have tried to troubleshoot and use the COLAXISTABLE statement- to no avail.
PROC SGPANEL DATA=lvmi;
PANELBY yearsincetx_grp / ROWS=1;
WHERE yearsincetx_grp=1 or yearsincetx_grp=2 or yearsincetx_grp=3;
VBOX lvmi / CATEGORY=im53 GROUP=sex displaystats=(N mean); *CSA;
ROWAXIS values= (20 to 120 by 10);
TITLE 'lvmi vs CSA by year and sex';
RUN;
Error code:
Which translates to:
NOTE: The DISPLAYSTATS= option is not supported for grouped box plots. The statistics is not created.
So in summary, does anyone know how I can display these statistics (mean, N) when I am using GROUP=sex in the VBOX statement?
Thanks in advance!
Sara
There is no need, and indeed reasons not to, make pictures of the log. It should be easier to copy log text and then on the forum open a text box, to preserve formatting, and then paste the text.
One reason with text is then we can copy bits out and provide details about what specific messages may mean in context.
https://support.sas.com/kb/56/520.html
Shows an example that uses additional variables added to the plot data set instead of attempting to plot the statistics using Displaystat to do so. The Colaxistable is restricted to Sum and Mean stats for Vbox (and many other plot types) so would need something other than the Stat options anyway.
You can work around this limitation by calculating the N and MEAN externally and using an AXISTABLE to display the values. Here is an example:
proc summary data=sashelp.heart nway;
class weight_status bp_status sex;
var cholesterol;
output out=table mean=mean n=n;
run;
data merged;
set sashelp.heart table;
run;
proc sgpanel data=merged;
panelby weight_status / novarname;
vbox cholesterol / category=bp_status group=sex;
colaxistable n mean / class=sex classdisplay=cluster
colorgroup=sex;
run;
Thanks for your reply! This works for adding in those statistics. However, my graph doesn't have the same formatting when I remove the grouping option for sex. See below.
What I want:
What I am getting from the adjusted code (no grouping variable for sex):
In order to avoid additional steps, I ended up going with your code adjustment after discussion with my team as this graphic was decided to be sufficient for our purposes. Thank you!
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.