Data visualization with SAS programming

Format Sgpanel Legend

Reply
Super Contributor
Posts: 494

Format Sgpanel Legend

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.

Super Contributor
Posts: 494

Re: Format Sgpanel Legend

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.

Super Contributor
Posts: 252

Re: Format Sgpanel Legend

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.

SAS Super FREQ
Posts: 3,615

Re: Format Sgpanel Legend

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

Super Contributor
Posts: 494

Re: Format Sgpanel Legend

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.

Super Contributor
Posts: 252

Re: Format Sgpanel Legend

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

Super Contributor
Posts: 252

Re: Format Sgpanel Legend

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.

SAS Super FREQ
Posts: 3,615

Re: Format Sgpanel Legend

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

Super Contributor
Posts: 494

Re: Format Sgpanel Legend

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

Super Contributor
Posts: 494

Re: Format Sgpanel Legend

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'

SAS Super FREQ
Posts: 3,615

Re: Format Sgpanel Legend

[ Edited ]

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?

Super Contributor
Posts: 494

Re: Format Sgpanel Legend

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.

Super Contributor
Posts: 494

Re: Format Sgpanel Legend

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

SAS Super FREQ
Posts: 3,615

Re: Format Sgpanel Legend

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;
Super Contributor
Posts: 494

Re: Format Sgpanel Legend

[ Edited ]

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.

Ask a Question
Discussion stats
  • 14 replies
  • 772 views
  • 0 likes
  • 3 in conversation