BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
genemroz
Quartz | Level 8

Is there a way within SAS to output to a new dataset all values of a variable that are, say, above the 90th percentile?  I know I can do it with manual intervention by using Proc Univariate to identify the 90th percentile and then, in a separate data step using a WHERE statement, output values greater than the 90th percentile value.  But I'm looking for a way to do it that doesn't require the manual intervention of coding the WHERE statement.

 

Thanks,

 

Gene

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

My bad, left something out, it should be

 

proc summary data=sashelp.baseball;
    var nhits;
    output out=stats p90=p90;
run;
data want;
    if _n_=1 then set stats;
    set sashelp.baseball;
    if nhits >= p90 then output;
run;
--
Paige Miller

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26
proc summary data=have;
     var yourvariablename;
     output out=stats p90=p90;
run;
data want;
    set have;
    if yourvariablename >= p90 then output;
run;
--
Paige Miller
genemroz
Quartz | Level 8

Thanks for the prompt reply.  I tried your suggested code but didn't get the desired result. I was expecting dataset want to contain only those players with more 163 hits (p90) but dataset want contains all 322 players.

See below:

proc summary data=sashelp.baseball;
var nhits;
output out=stats p90=p90;
run;
data want;
set sashelp.baseball;
if nhits >= p90 then output;
run;
PaigeMiller
Diamond | Level 26

My bad, left something out, it should be

 

proc summary data=sashelp.baseball;
    var nhits;
    output out=stats p90=p90;
run;
data want;
    if _n_=1 then set stats;
    set sashelp.baseball;
    if nhits >= p90 then output;
run;
--
Paige Miller
genemroz
Quartz | Level 8
Excellent! Thanks!
Ksharp
Super User

For having some fun.

 


proc rank data=sashelp.baseball out=temp groups=100;
var nhits;
ranks rank;
run;
data want2;
 set temp;
 if rank>88;
 drop rank;
run;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 322 views
  • 0 likes
  • 3 in conversation