BookmarkSubscribeRSS Feed
lifelearner2015
Fluorite | Level 6

Generally I want to use "class group;" to output means for "group1, group2, ....group10" like:

Group      mean    

group1       ..

group2      ..

...               ..

group9      ..

group10    ..

 

however, if using just "class group;", the output is like:

Group      Mean    

group1       ..

group10     ..

...                ..

group8       ..

group9       ..

 

group10 was not output at the bottom, but instead, it showed after group1. 

How can it be coded so that group10 is at the bottom. thank you very much.

 

2 REPLIES 2
ballardw
Super User

This is a common issue with character variables. You have  couple of options. One is the be very conscious of using Group01 instead of Group1 though that may be difficulate to use as an approach if you don't know ahead of time that you're going to need Group0001 ...

The next to create your summaries into a data set. Then use proc sort with the SORTSEQ option Numeric_collation=On

 

proc sort data=have sortseq=linguistic(numeric_collation='ON'); by group;run;

and then print.

 

I'm not sure if any of the report procedures directly support the option.

 

The other approach is create a variable that always sorts in the order you want and then use a custom display format to diplay the desired value. Some times the new variable is easiest to create with a custom informat:

 

proc format ;

invalue group

"group1" = 1

"group2" = 2

...

"group10" = 10;

value group

1 = "group1"

2 = "group2"

...

10= "group10"

;

run;

 

data want;

   set have;

   newgroup = input(group,group.);

   format newgroup group.;

run;

 

proc means data=want ;

   class newgroup /order=unformatted;

   var analysisvar;

run;

 

lifelearner2015
Fluorite | Level 6

many thanks! 🙂

Spoiler
 

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
  • 2 replies
  • 732 views
  • 1 like
  • 2 in conversation