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.
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....
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
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?
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;
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.