BookmarkSubscribeRSS Feed
Jaime
Fluorite | Level 6
I am using the below code to drisplay 3 charts for the level variable.
The procedure sorts the levels alphabetically. I want to force another order. Is there a way to do this?


proc sgpanel data=to_plot;
panelby level/columns=1;
vbar time/response=ratio datalabel ;
format ratio percent.;
run;
3 REPLIES 3
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Suggest doing a Google advanced search against the SAS.COM support website - here is one that works quite well for this post:

sgpanel panelby sort order site:sas.com

Scott Barry
SBBWorks, Inc.
Jaime
Fluorite | Level 6
Scott,

Thanks for your “Google it” suggestion. However, I was unable to find the answer I was looking for. Maybe I’m missing something.
I am trying to use proc format to order the panel outcome of the sgpanel. Similar to how you would use it to order a variable in proc report using a specific order. It’s not alphabetical nor numerical.

Cheers.
GraphGuy
Meteorite | Level 14
If you're comfortable with user-defined formats, you could assign numeric values to the "level", which would be used to control the order of the charts, and then have the user-defined format print those numeric values as the desired text (the charts will be ordered by the pre-formatted numeric values).

Here is a variations of your code that demonstrates this:

proc format;
value my_fmt
1 = "ZZZ"
2 = "MMM"
3 = "AAA"
;
run;

data to_plot;
format level my_fmt.;
input level time ratio;
datalines;
1 1 .2
1 2 .25
1 3 .33
2 1 .6
2 2 .55
2 3 .67
3 1 .11
3 2 .22
3 3 .25
;
run;

proc sgpanel data=to_plot;
panelby level/columns=1;
vbar time/response=ratio datalabel ;
format ratio percent.;
run;



And, if you're really comfortable with user-defined formats, you can even create the format in a data-driven manner, using a "cntlin" data set.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2491 views
  • 0 likes
  • 3 in conversation