BookmarkSubscribeRSS Feed
alawatnuk
Calcite | Level 5

I am creating a bar chart with stacked and clustered groups using SGPanel and need a way to create separate legends for each of the panels. 

 

This is how I am graphing it:

proc sgpanel data=DATASET;
  title 'TEST GRAPH';
  panelby var / layout=columnlattice novarname noborder colheaderpos=bottom columns=3;
  vbar year / response=percent group=bin;
  colaxis display=(nolabel) valueattrs=(size=6);
  rowaxis label="Percent" grid valueattrs=(size=6) labelattrs=(size=6);
  run;

The issue is that within each panel, there are different "bins" so the single legend is massive.  An example output graph is attached of what I currently have. I want to instead have a separate legend for each panel (which uses the same colors in each panel for different values).

 

test.png

 

3 REPLIES 3
DanH_sas
SAS Super FREQ

Your better option, in this case, might be to just use a BY-group with SGPLOT. something like this (you might need to PROC SORT your BY var):

 

proc sgplot data=DATASET;
  title 'TEST GRAPH';
  by var;
  vbar year / response=percent group=bin;
  xaxis display=(nolabel) valueattrs=(size=6);
  yaxis label="Percent" grid valueattrs=(size=6) labelattrs=(size=6);
  run;

You can then use ODS LAYOUT if want them generated side-by-side.

 

Hope this helps!
Dan

alawatnuk
Calcite | Level 5

Hi DanH_sas, 

 

Thanks so much for your response!

 

I tried a bygroup with SGPlot, but what im really looking for is one cohesive plot like SGPanel produces (one single y axis and x axis). Additionally, with ODS Layout I am not able to output the three graphs side by side as one single .png. Any recommendations on how to do the above with SGPlot and ODS Layout? 

 

 

DanH_sas
SAS Super FREQ

Since your requirement is for the output to be in one PNG file, the three legends you are proposing would actually take up the same area (or more due to extra titles) in the graph as the one legend you are getting now. So, I'm not sure what you're trying to accomplish. Can you explain further?

sas-innovate-white.png

🚨 Early Bird Rate Extended!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Lock in the best rate now before the price increases on April 1.

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
  • 3 replies
  • 1810 views
  • 2 likes
  • 2 in conversation