Graphics Programming

Data visualization using SAS programming, including ODS Graphics and SAS/GRAPH. Charts, plots, maps, and more!
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
stodo53
Obsidian | Level 7

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
Obsidian | Level 7

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
Obsidian | Level 7

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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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