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

What is the best way to sort - by descending mean - the output of PROC MEANS with multiple variables?

 

PROC MEANS DATA=sas_communities MAXDEC=1; 
VAR thc_ssx_vas_anx--thc_ssx_vas_other; 
RUN;

 

proc means unsorted.jpg 

I tried outputting the summary stats to a new data set, but the output of the PROC PRINT is one long row (See below).

PROC MEANS DATA=sas_communities MAXDEC=1;
	VAR 
	thc_ssx_vas_anx--thc_ssx_vas_other;
	
	OUTPUT OUT 		= thc_ssx_vas_summary (DROP = _:)
          n 	(thc_ssx_vas_anx--thc_ssx_vas_other) = 
          mean  (thc_ssx_vas_anx--thc_ssx_vas_other) = 
          std	(thc_ssx_vas_anx--thc_ssx_vas_other) = 
          min  	(thc_ssx_vas_anx--thc_ssx_vas_other) = 
          max   (thc_ssx_vas_anx--thc_ssx_vas_other) = ;      
RUN;

proc print.jpg

 

Thank you.  Dataset attached.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

there are two ways, both described in the article "Save descriptive statistics for multiple variables in a SAS data set."

 

The one that uses PROC MEANS would look something like this:

 

ods exclude all;                  /* suppress display to open ODS destinations */
proc means data=sashelp.cars 
           N Mean Std Min Q1 MEDIAN Q3 Max  /* type every statistic you want */
           STACKODSOUTPUT;        /* preserve table form of output */
var _NUMERIC_;
ods output Summary=MeansSummary;  /* write statistics to data set */
run;
ods exclude none;  

proc sort data=MeansSummary;
by descending Mean;
run;

proc print data=MeansSummary noobs;
format _NUMERIC_ BESTD6.;
var Variable N Mean StdDev Min Max;
run;

View solution in original post

4 REPLIES 4
Rick_SAS
SAS Super FREQ

there are two ways, both described in the article "Save descriptive statistics for multiple variables in a SAS data set."

 

The one that uses PROC MEANS would look something like this:

 

ods exclude all;                  /* suppress display to open ODS destinations */
proc means data=sashelp.cars 
           N Mean Std Min Q1 MEDIAN Q3 Max  /* type every statistic you want */
           STACKODSOUTPUT;        /* preserve table form of output */
var _NUMERIC_;
ods output Summary=MeansSummary;  /* write statistics to data set */
run;
ods exclude none;  

proc sort data=MeansSummary;
by descending Mean;
run;

proc print data=MeansSummary noobs;
format _NUMERIC_ BESTD6.;
var Variable N Mean StdDev Min Max;
run;
Peter_C
Rhodochrosite | Level 12

missed Rick's post while I was away

 

While the STACKODSOUTPUT solves some needs, a SAS conference paper can be found with a macro named %better_means.

See       http://support.sas.com/resources/papers/proceedings12/231-2012.pdf

 

The macro solves the problem of generating stats of differing data types within a column by converting values to strings in appropriate formats

 

unfortunately the macro source code isn't short, and not easily extracted from the paper, so I've attached it here

Vella_Liu
Calcite | Level 5

I have a similar problem: how to sort the means of a variable in descending order? My goal is to organize the 2nd table (see output below), sort the table in the order of descending mean, so 965 at the bottom while 979 at the top. I tried the method using proc sort (see my code) but the program didn't recognize Mean as a variable.

 

Thank you so much for all of your help!

 

proc means data=pg1.storm_final 
		   N Mean Min maxdec=0;
	var MinPressure;
	ods output Summary=N_avg_min_Summary;
	where Season >=2010;
	class Season Ocean;
	ways 1;
run;

proc sort data=N_avg_min_Summary;
by descending Mean;
run;

 Screen Shot 2021-05-30 at 1.03.45 PM.png

Rick_SAS
SAS Super FREQ

 

You have to LOOK at the output data set and determine the names of the variables for your data and analysis. For your example, try the following:

 

 

 

proc sort data=N_avg_min_Summary out=SeasonMeans;
where not missing(Season);
by descending MinPressure_Mean;
run;

proc print data=SeasonMeans; run;

 

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 20733 views
  • 7 likes
  • 4 in conversation