DATA Step, Macro, Functions and more

Proc Means Var Statement

Accepted Solution Solved
Reply
Occasional Contributor bzh
Occasional Contributor
Posts: 7
Accepted Solution

Proc Means Var Statement

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!


Accepted Solutions
Solution
‎12-30-2015 01:32 PM
Super User
Posts: 5,081

Re: Proc Means Var Statement

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


All Replies
Frequent Contributor
Posts: 130

Re: Proc Means Var Statement

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;
Solution
‎12-30-2015 01:32 PM
Super User
Posts: 5,081

Re: Proc Means Var Statement

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.

Super User
Posts: 17,785

Re: Proc Means Var Statement

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.
Occasional Contributor bzh
Occasional Contributor
Posts: 7

Re: Proc Means Var Statement

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...

 

 

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 371 views
  • 0 likes
  • 4 in conversation