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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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