SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
mariko5797
Pyrite | Level 9

I am trying to tweak the code from here: https://support.sas.com/kb/56/520.html to match my data. However, I have ran into some unexpected issues. 

  1. Median (Min-Max) and Mean(STD) are not showing up in the colaxis table. Is this because they are stored as character? Do the values have to be numeric?
  2. Not all the box plots are centered. Is there a way to fix this?
  3. Not really an issue, but is there a way to have "BMI category" on top of the graph rather than the bottom?

Thank you in advance!

 

Data:

mariko5797_1-1630073801584.png

 

Code & Output:

ods graphics / reset width = 750px height = 460px noscale attrpriority = none;
proc sgpanel data = workstats;
 panelby BMIGRP / novarname columns = 3;
 vbox ADJDV / category = BMIGRP;
 colaxis display = (noticks novalues);
 colaxistable _CNT_ / label = 'N' position = bottom separator
				  valueattrs = (size=10) labelattrs = (size=10);
 colaxistable MEAN_STD / label = 'Mean(sd)' position = bottom 
				  valueattrs = (size=10) labelattrs = (size=10);
 colaxistable MED_RANGE / label = 'Median(Min - Max)' position = bottom 
				  valueattrs = (size=10) labelattrs = (size=10);
run;

mariko5797_0-1630073218223.png

 

4 REPLIES 4
mariko5797
Pyrite | Level 9

The character values still don't show. Do they have to be numeric to show in the table?

Ksharp
Super User
Yes. Mean Min Max should be numeric .
ballardw
Super User

@mariko5797 wrote:

I am trying to tweak the code from here: https://support.sas.com/kb/56/520.html to match my data. However, I have ran into some unexpected issues. 

  1. Median (Min-Max) and Mean(STD) are not showing up in the colaxis table. Is this because they are stored as character? Do the values have to be numeric?
  2. Not all the box plots are centered. Is there a way to fix this?
  3. Not really an issue, but is there a way to have "BMI category" on top of the graph rather than the bottom?

 


1) You might try an INSET statement.

2) Centered which way? All of the elements on a single row have the same Y-axis definition. If you want things vertically centered you will need to place them on different rows and not use the same scale for each row (the default) and then hope the results are "centered". Differing ranges of outliers means that is almost never going to happen.

 

If you want things centered horizontally then the X axis value would have to be the same for each box if it is numeric.

If you remove the NOVALUES on the Colaxis statement you will see the offsets are caused by the values of the BMIGRP variable.

Below is an example of adding a variable to create a horizontally centered boxes.

proc sgpanel data = sashelp.class;
 panelby sex / novarname ;
 vbox age / category = sex;
 colaxis ;
run;

data alt;
   set sashelp.class;
   dummy=1;
run;

proc sgpanel data = alt;
 panelby sex / novarname ;
 vbox age / category = dummy;
 colaxis ;
run;

3) I don't find an option to move the label to the top. You could suppress the text and use a annotate data set to add text above the graph.

 

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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
  • 4 replies
  • 1190 views
  • 0 likes
  • 3 in conversation