BookmarkSubscribeRSS Feed
DavidPhillips2
Rhodochrosite | Level 12

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.

14 REPLIES 14
DavidPhillips2
Rhodochrosite | Level 12

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.

djrisks
Barite | Level 11

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.

Rick_SAS
SAS Super FREQ

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

DavidPhillips2
Rhodochrosite | Level 12

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.

djrisks
Barite | Level 11

I am curious, why would not this work now? What results for the legend are you getting in SGPANEL?

djrisks
Barite | Level 11

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.

Rick_SAS
SAS Super FREQ

From what you've said, I suggest the "fake data trick" and using GROUPORDER=DATA

DavidPhillips2
Rhodochrosite | Level 12

I have a syntax issue apparently sgpanel works the same for ordering as sgplot.

DavidPhillips2
Rhodochrosite | Level 12

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'

Rick_SAS
SAS Super FREQ

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?

DavidPhillips2
Rhodochrosite | Level 12

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.

DavidPhillips2
Rhodochrosite | Level 12

Googling syntax for group order the option does not come up with intelsense in 9.4.

Rick_SAS
SAS Super FREQ

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;
DavidPhillips2
Rhodochrosite | Level 12

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 14 replies
  • 2326 views
  • 0 likes
  • 3 in conversation