BookmarkSubscribeRSS Feed
koyelmukherjee2
Calcite | Level 5

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;

4 REPLIES 4
art297
Opal | Level 21

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

 

koyelmukherjee2
Calcite | Level 5

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?

art297
Opal | Level 21

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

 

 

 

ballardw
Super User

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;

 

sas-innovate-2024.png

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.

 

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
  • 4476 views
  • 2 likes
  • 3 in conversation