- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
And you could try add SEX into PANELBY statement.
proc sgpanel;
PANELBY yearsincetx_grp sex/layout=lattice;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
And you could try add SEX into PANELBY statement.
proc sgpanel;
PANELBY yearsincetx_grp sex/layout=lattice;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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):
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Did you try @DanH_sas code ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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!