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

I have an order transactions data set with one million records.  Among the list of order records and variables, there is a GROUP variable which is a classifier and an ITEMS variable which is a numerical integer.  My goal is to make a table that displays the top 10 GROUPs with the highest mean ITEMS.  I will try to give you an example data set:

order_id, group_id, items;

1, A, 6;

2, D, 12;

3, B, 15;

4, A, 10;

5, C, 2;

6, B, 14;

7, F, 4;

8, B, 9;

9, A, 24;

10, D, 12;

 

I imagine I need to use a combination of PROC MEANS, PROC SORT, and PROC PRINT, but I have tried these in combinations with no success. 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
proc summary data=have nway;
    class group_id;
    var items;
    output out=_means_ mean=;
run;
proc sort data=_means_ out=want;
    by descending items;
run;

This doesn't give the TOP N means, it gives you all means in descending order; but you can get the TOP N means easily from data set WANT in a DATA step.

--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26
proc summary data=have nway;
    class group_id;
    var items;
    output out=_means_ mean=;
run;
proc sort data=_means_ out=want;
    by descending items;
run;

This doesn't give the TOP N means, it gives you all means in descending order; but you can get the TOP N means easily from data set WANT in a DATA step.

--
Paige Miller
tmccombs27
Calcite | Level 5

Thank you!

I applied this to my data set and I have what I wanted.  I used proc print to get my top 10 for display.  I have not used proc summary before, and I kept trying to use by where I should have used class.  I also would have never guessed that I could define a statistic within the OUT statement.

 

 

PaigeMiller
Diamond | Level 26

PROC SUMMARY is 99% the same as PROC MEANS. The default outputs are different, SUMMARY defaults to output to a SAS data set, MEAN defaults to output as text in HTML or LISTING.

--
Paige Miller

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 366 views
  • 0 likes
  • 2 in conversation