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