03-16-2016 11:11 AM
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.
03-16-2016 11:13 AM
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.
03-16-2016 11:13 AM
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....
03-16-2016 11:16 AM
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.
03-16-2016 11:22 AM
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.
03-16-2016 02:51 PM
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;
keylegend / title="titletest";
format hs_gpa_range Rankingc.;
with one dataset high school gpa is ordered correctly
with another dataset high school gpa is ordered
03-16-2016 03:13 PM - edited 03-16-2016 03:29 PM
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?
03-16-2016 03:15 PM
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.
03-16-2016 03:27 PM
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;
03-16-2016 03:29 PM - edited 03-16-2016 03:33 PM
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.