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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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