How can I format a sgpanel legend? I’m trying to order the values in the legend. The format tricks that I use with other graphics does not seem to be working.
normally I use stuff like: https://communities.sas.com/t5/SAS-GRAPH-and-ODS-Graphics/SGPLOT-legend-order/m-p/233202#M8455 but this doesn't appear to work with sgpannel.
Hi, can you use the SORTORDER=ASCENDING option in keylegend?
I thought the formats should work anyway? Another approach is to add a 1, 2 or 3 in front of your legend label.
Do you mean "apply a format" or do you mean "position a legend" or do you mean "specify the order of a legend"?
Hard to know what "tricks" you've tried, so please supply data and example.
You can use a trick to include (and order) categories in SGPLOT legends. There are many other tricks, such as http://blogs.sas.com/content/iml/2012/10/17/specify-the-colors-of-groups-in-sas-statistical-graphics....
What I did for sgplot is I created my data as numeric and made formats to order them. Then when they are formatted they appear in custom ordering. I need more control over the ordering than descending or ascending.
I am curious, why would not this work now? What results for the legend are you getting in SGPANEL?
Maybe there is missing data? I think sorting the dataset by the group variable might help too. There are some tricks though, which Rick has linked too.
From what you've said, I suggest the "fake data trick" and using GROUPORDER=DATA
I have a syntax issue apparently sgpanel works the same for ordering as sgplot.
proc format;
value Rankingc
1='Over 4.0'
2='3.51-4.0'
3='3.01-3.5'
4='2.51-3.0'
5='2.01-2.5'
6='0-2.0'
7='Unknown'
97=' '
98='Subtotal'
99='Total'
100='growthDeclineText'
101='perGrowthDeclineText';
run;
title;
proc sgpanel data=enrollment;
panelby residency_desc gender/ layout=lattice uniscale=column novarname columns=2 onepanel;
vbar four_digit_year / response=enrolled nostatlabel
group = hs_gpa_range;
rowaxis display=(nolabel);
colaxis display=(nolabel);
keylegend / title="titletest";
format hs_gpa_range Rankingc.;
run;
with one dataset high school gpa is ordered correctly
with another dataset high school gpa is ordered
'Over 4.0'
'3.51-4.0'
'3.01-3.5'
'2.51-3.0'
'2.01-2.5'
'Unknown'
'0-2.0'
In the VBAR statement, the default group ordering is GROUPORDER=ASCENDING, which means that the bars should appear according to the unformatted values of the HS_GPA_RANGE variable.
The behavior you describe shouldn't occur if you are using GROUPORDER=ASCENDING, but it could happen for different data sets if you are using GROUPORDER=DATA. Very strange. Double check the SAS Log to validate the options that you are using. Maybe explicitly set the GROUPORDER= option?
This bug also affects proc report based on the dataset. Oddly some sections of proc report are ordered correctly and others are not in the same report. This occurs when using three columns on the left in proc report.
Googling syntax for group order the option does not come up with intelsense in 9.4.
Here is some simulated data. The SGPANEL procedure works properly on this data set.
data enrollment;
do residency_desc = 0 to 1;
do gender = 0 to 1;
do i = 12 to 16;
four_digit_year = 2000 + i;
do hs_gpa_range=1 to 7;
enrolled = int(1000*rand("Uniform"));
output;
end;
end;
end;
end;
run;
With grouporder sgpanel works. Looking at the same bug in proc report, going to see if it allows sortorder too.
sortorder orders by the post formated values.
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.