BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
stodo53
Calcite | Level 5

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. 

saratodorovic_0-1714053164124.png

 

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:

saratodorovic_1-1714053314613.png

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 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
If I was right, you are unable to use option "displaystats=" when you have option "group=", Check its DOC.
And you could try add SEX into PANELBY statement.

proc sgpanel;
PANELBY yearsincetx_grp sex/layout=lattice;

View solution in original post

6 REPLIES 6
ballardw
Super User

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.

DanH_sas
SAS Super FREQ

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;
Ksharp
Super User
If I was right, you are unable to use option "displaystats=" when you have option "group=", Check its DOC.
And you could try add SEX into PANELBY statement.

proc sgpanel;
PANELBY yearsincetx_grp sex/layout=lattice;
stodo53
Calcite | Level 5

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:

saratodorovic_0-1714123858606.png

What I am getting from the adjusted code (no grouping variable for sex):

saratodorovic_1-1714123889646.png

 

Ksharp
Super User
Yeah. That is what supposed to do.
Did you try @DanH_sas code ?
stodo53
Calcite | Level 5

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!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 343 views
  • 7 likes
  • 4 in conversation