BookmarkSubscribeRSS Feed
Calcite | Level 5 GDA
Calcite | Level 5
Hi all

I am trying to create what I believe to be a relatively simple set of boxplots. I want to be able to group the x-axis by certain variables. Then the legend should show the differences.

For example.

I am plotting the "number of errors" on the y-axis vs 2 variables on the x. First one being "Test_Time_bin" and second being "Substrate" The number of values for both Test_Time and Substrate will change for every dataset I am going to plot so I cannot hard code anything. For each value of "Test_Time_Bin" I want multiple boxplots (side by side) for each value of "Substrate".

I have searched around and haven't had any luck with finding example code. I did find a picture of the exact thing I want to do for reference. Figure 2 at this link:

Hope I am explaining enough here.

Meteorite | Level 14
With traditional SAS/Graph "proc gchart", you can do grouped bar charts, and turn on the 'errorbar' on each bar, and get something a little bit similar (not exactly what you're wanting though). For example:

axis1 value=(angle=90);
pattern1 v=s c=yellow;

proc gchart data=sashelp.revhub2;
vbar type / type=mean sumvar=revenue errorbar=both
group=hub space=0 gspace=5 maxis=axis1;

To get something more like the graph in your link, you'd have to pre-calculate everything, and then put together a special data set to do a grouped bar, with a "floating" bar segment for the yellow part (by 'floating', I mean the lower of the 2 segments would be the same color as the background, making it 'invisible', such as ... ). And then annotate the box plot onto each of the bars (you'd need to pre-calculate the y-value for each of the pieces of the boxplot to use to construct your box plot: mean, lower, upper, etc). It would be a bit "cumbersome" 🙂

Maybe/hopefully one of the new ODS Graphics procs provides an easier solution(?) 🙂
If you are running SAS 9.2, try something like the code below to see if this is what you want:

proc sgpanel data=your_data;
panelby test_time_bin / layout=columnlattice noborder onepanel;
vbox your_subval_variable / category=Substrate;

There are other ways to tweak this example, but let me know if this the general form of what you want.

Calcite | Level 5 GDA
Calcite | Level 5
Thanks Fellas!

I don't like the idea of having to jump through too many hoops to get at what I want so I'm going to explore the SGPANEL solution, which is very close to what I want.

After I plugged in my data set, I would like 2 additional changes (if possible). #1 is kind of a show stopper and number 2 is just a nicety.

1. I need the panelby variable (test_time_bin) to display only the values on the graph. It is currently combining the variable name + the value. For example I need it to be "a. 0-100 hrs" instead of "Test_Time_Bin = a. 0-100 hrs", etc..... The data actually gets cut off unless I create a huuuuuuuuuuge graph, which I don't want to do.

2. I would like to get this entire group of panelby groups to the bottom of the graph instead of the top.

Boy I sure wish this forum would accept pictures so I could clearly explain what I'm looking for. Let me know if you need more info.

here's the code so far.

ods graphics / reset width=1200px height=700px MAXLEGENDAREA=50 IMAGEMAP=On;
ods html file='test.html' path="C:\" style=Festival;
title "Test Boxplots";

proc sgpanel data=WORK.BER_Deltas_with_Attributes ;
panelby test_time_bin / layout=columnlattice noborder onepanel;
vbox Num_Soft_Errs_delta / category=SBR_c;

ods html close;
1. Use the NOVARNAME option on the PANELBY statement.

2. Use the COLHEADERPOS=BOTTOM option on the PANELBY statement.




Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg



Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 4 replies
  • 3 in conversation