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

Innovate_SAS_Blue.png

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