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

Sample data below, say, here is 100 rows/group, need to get the average of X in each group with excluding

the top 10 values?! 

 

data temp; do i=1 to 1000; grp=floor((i-1)/100)+1; x=ranuni(i); output; end; run;quit;

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Don't use SQL for this, use PROC RANK (Maxim 14: Use the right tool). The benefit is that PROC RANK makes this simple, and furthermore gives you several options for handling ties.

 

proc rank data=temp groups=10 out=deciles;
    by grp;
    var x;
    ranks decile;
run;

proc means data=deciles;
    by grp;
    where decile < 9;
    var x;
run;

 

 

--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Don't use SQL for this, use PROC RANK (Maxim 14: Use the right tool). The benefit is that PROC RANK makes this simple, and furthermore gives you several options for handling ties.

 

proc rank data=temp groups=10 out=deciles;
    by grp;
    var x;
    ranks decile;
run;

proc means data=deciles;
    by grp;
    where decile < 9;
    var x;
run;

 

 

--
Paige Miller
hellohere
Pyrite | Level 9

Thanks a huge. Anyway to do a list of variables, and save out the means into a dataset?!

PaigeMiller
Diamond | Level 26

Yes, you can use variable lists in both PROC RANK and PROC MEANS. PROC MEANS also allows you to create output data sets.

--
Paige Miller

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 3 replies
  • 637 views
  • 1 like
  • 2 in conversation