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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 4 replies
  • 2046 views
  • 3 likes
  • 3 in conversation