DATA Step, Macro, Functions and more

How to sort proc means when using class

Reply
New Contributor
Posts: 2

How to sort proc means when using class

Hi All,

 

I need to sort my output in the descending order of mean. Please help.

 

data average;
set sashelp.cars (KEEP = MAKE MODEL MSRP);
run;

 

 

proc means data = average mean nway nonobs;
class make;
var msrp;

run;

PROC Star
Posts: 7,362

Re: How to sort proc means when using class

Easy to do with proc sql:

 

proc sql;
  select make,mean(msrp) as mean format=dollar7.
    from sashelp.cars
      group by make
        order by mean descending
  ;
quit;

HTH,

Art, CEO, AnalystFinder.com

 

New Contributor
Posts: 2

Re: How to sort proc means when using class

Hello,

 

Thanks for the reply. But, I wanted to know if there is a way to do it using PROC MEANS descend /descending. Is it not allowed while using class?

PROC Star
Posts: 7,362

Re: How to sort proc means when using class

Not that I'm aware of. AFAIK, all of the order by options are related to the class or by values or their frequency or formatted values.

 

Art, CEO, AnalystFinder.com

 

 

 

Super User
Posts: 10,490

Re: How to sort proc means when using class

Since you want "I need to sort my output in the descending order of mean" then create an output data set and sort that;

 

 

proc summary data=SASHelp.cars nway;

   class make;

   var msrp;

   output out = average (drop = _type_ _freq_) mean=;

run;

proc sort data=average;

   by descending msrp;

run;

 

Ask a Question
Discussion stats
  • 4 replies
  • 156 views
  • 0 likes
  • 3 in conversation