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
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;
proc summary data=have;
var yourvariablename;
output out=stats p90=p90;
run;
data want;
set have;
if yourvariablename >= p90 then output;
run;
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;
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;
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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.