- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
proc summary data=have;
var yourvariablename;
output out=stats p90=p90;
run;
data want;
set have;
if yourvariablename >= p90 then output;
run;
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;