I have a proc gchart and have a Legend. The proc outputs barcharts with subgroups. Like goup A with three bars,x,y,z Group B with xxy,z etc. In my case the order of the bars matter ( x needs to go first). How can I make the legend display the same order of the bars.RIght now, no matter what I do, it will display the legend with the color of y then z and then x. I tried many different things and nothing.Any help greatly appreciated. Thanks
I assume you're wanting the legend colors to be 'stacked' in the same order as the bar segments are stacked(?)...
If you're re-using the same code with different data, sometimes it's not practical to hard-code the desired legend order (you would need to keep re-hard-coding the legend values as the data changes, or do something tricky to generate it dynamically in a macro variable).
Therefore, in 9.3 we've added the new "descending" option for the gchart legend -- it allows you to easily get the legend in descending order (whereas it's usually in ascending order). Here's a little example & explanation:
Yes, it is the colors that should be ordered the same way as the bars. I should have been more clear. For example, if red is first, the color in the legend should be red first. I did the order as mentioned by Art297 but noticed the colors did not want to get ordered. Any samples on ordering in 9.2 ?
You would have to hard-code the legend order in 9.2, such as ...
input Salesman $ 1-6 Year Sales;
Bob 2009 6
Anna 2009 8
Carl 2009 9
Bob 2010 7
Anna 2010 9
Carl 2010 10
axis1 label=none order=(0 to 30 by 10) minor=none offset=(0,0);
axis2 label=none offset=(15,15);
legend1 position=(right middle) across=1 label=none
shape=bar(.13in,.13in) order=('Carl' 'Bob' 'Anna');
pattern1 v=s c=yellow;
pattern2 v=s c=orange;
pattern3 v=s c=red;
proc gchart data=a;
vbar year / discrete type=sum sumvar=sales
raxis=axis1 maxis=axis2 width=15 space=8
noframe autoref clipref cref=graycc
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.
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.