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

Innovate_SAS_Blue.png

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. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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