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