BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
bzh
Fluorite | Level 6 bzh
Fluorite | Level 6

Hello,

I have a data set with 100s of numeric variables that are similar in nature. To create a simple list report about their averages I have used Proc Means:

 

proc means data=have;

   var _numeric_;

run;

 

The SAS documentation for the Var Statement reads:  "Identifies the analysis variables and their order in the output."

 

When using "_numeric_" in the Var Statement to avoid listing 100s of variables, is there any way to control their order in the output?  In this situation, the ideal list report would show the variables in descending order of the Mean.  I'm sure there's a proc means output --> data step with array --> proc sort --> proc print solution for this, but I wanted to see if Proc Means has the capability.

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

PROC MEANS doesn't have the capability.

 

Even in theory, building that capability would involve major work.  Remember, PROC MEANS can use both a BY statement and a CLASS statement.  Should the order change from one value of a BY variable to the next?  It becomes a very sticky problem, very quickly.

View solution in original post

4 REPLIES 4
dcruik
Lapis Lazuli | Level 10

You can always output the data set and then run a sort procedure after the means procedure.  It's in two steps instead of one, but will still get you what you are wanting.

 

data means data=have noprint;
var _numeric_;
output out=want
mean=Mean;
run;

proc sort data=want;
by descending Mean;
run;
Astounding
PROC Star

PROC MEANS doesn't have the capability.

 

Even in theory, building that capability would involve major work.  Remember, PROC MEANS can use both a BY statement and a CLASS statement.  Should the order change from one value of a BY variable to the next?  It becomes a very sticky problem, very quickly.

Reeza
Super User
Use proc means with the stackods option to get the data in a long format by default. Then you can sort directly without arrays or any other intermediate steps.
bzh
Fluorite | Level 6 bzh
Fluorite | Level 6

Thanks Everyone!  I chose Astounding's response as the answer as it confirms that Proc Means cannot sort variables if "_numeric_" is in the Var Statement.

However, Reeza's reply is the best solution for the report I need to build.  Here is a SAS 9.4 link that goes with Reeza's stackods suggestion:

 

https://support.sas.com/documentation/cdl/en/proc/68954/HTML/default/viewer.htm#p17h6q7ygvkl1sn13qzf...

 

 

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
  • 4 replies
  • 2815 views
  • 0 likes
  • 4 in conversation