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: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 2572 views
  • 3 likes
  • 3 in conversation