BookmarkSubscribeRSS Feed
wernie
Quartz | Level 8

I'm trying to get the min, median, and max for populations for 8 states classified by two methods. The code I tried only seems to allow me to add one of those (e.g., median) for visualisation. Image attached to show example graph. Is there a way to get min/med/max by state AND by method on a graph? Not sure if there is some kind of panel method that would be better showing min/med/max for each method by state. Thanks!

 


proc sgplot data=Graph_test1;
    vbar State / response=Median group=method groupdisplay=cluster;
    yaxis label="Population";
    title 'Test';
run;
title;

4 REPLIES 4
DanH_sas
SAS Super FREQ

PROC SGPANEL should give you that extra level of classification you need. Try something like this:

 

proc sgpanel data=Graph_test1;
   panelby method / columns=1 onepanel;
   vbar State / response=min discreteoffset=-0.3 barwidth=0.3;
   vbar State / response=median barwidth=0.3;
   vbar State / response=max discreteoffset=0.3 barwidth=0.3;
   rowaxis label="Population";
run;

Hope this helps!

Dan

wernie
Quartz | Level 8

Thank you! That definitely helps. One additional question - my max is quite high, so it doesn't allow for the variation in min or median to be seen. Is there a way to add a secondary y axis in this code? Thanks again.

DanH_sas
SAS Super FREQ

In SGPLOT, we support both secondary axes and axis breaks. I would recommend trying the axis breaks, as the visual comparison of the max bars against the other two bars might be confusing with a secondary axis. Here is simple example using axis breaks:

 

proc sgplot data=sashelp.cars;
yaxis ranges=(0-300000 800000-max);
vbar type / response=weight;
run;

Using SGPLOT would mean that you will need to move the METHOD variable to a BY-group:

 

proc sgplot data=Graph_test1 uniform=all; /* for uniform axes and groups */
   by method / columns=1 onepanel;
   vbar State / response=min discreteoffset=-0.3 barwidth=0.3;
   vbar State / response=median barwidth=0.3;
   vbar State / response=max discreteoffset=0.3 barwidth=0.3;
   yaxis label="Population"; /* Add your RANGES option here */
run;

Hope this helps!

Dan

Jay54
Meteorite | Level 14

From your code it would seem you may have the response values computed in your data set as separate columns.  You can use other plot types to overlay the other columns.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 2512 views
  • 3 likes
  • 3 in conversation