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!
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.
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;
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.
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:
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.