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

Thus, filtering away the lowest 75%, based on a particular variable, and leaving just the top 25% in the new sub-dataset.

 

Can we actually use the "where" clause for this?

 

Wondering how you folks might handle it:

data want;
set have;
where
top_25_percent_in_column = ??? ;
run;

Perhaps there isn't currently a SAS 'function' for such a purpose?

 

If you feel SAS is a bit function-lacking, say so.  Can the equivalent be found by using Python or R within SAS?  Never tried using either in SAS, but I understand there are thousands of Python and R functions.

 

Thoughts appreciated....

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Paige already gave you a solution.

Another way is calcualted Q3 firstly and keep the top 25% via it .

 

data have;
set sashelp.heart;
run;

proc summary data=have;
var weight;
output out=Q3 q3=q3;
run;

data want;
 set have;
 if _n_=1 then set q3(keep=q3);
 if weight>=q3 ;
 drop q3;
run;

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

I assume you want the top 25 percentile (rather than top 25%, I don't know what that means).

 

proc rank data=have groups=4 out=want descending;
    var yourvariablename;
    ranks rank;
run;

 

You want any record in WANT where variable RANK is equal to zero.

 

--
Paige Miller
Reeza
Super User

@PaigeMiller wrote:

I assume you want the top 25 percentile (rather than top 25%, I don't know what that means).

 

proc rank data=have groups=4 out=want (where = (rank=3)) descending;
    var yourvariablename;
    ranks rank;
run;

 

You want any record in WANT where variable RANK is equal to zero.

 


Note you can modify @PaigeMiller solution with a WHERE statement to have the data filtered. 

 

Percentiles and 25% of data don't necessarily align though so you should be clear on the differences and if it meets your needs, especially if you have ties in your data. 

Ksharp
Super User

Paige already gave you a solution.

Another way is calcualted Q3 firstly and keep the top 25% via it .

 

data have;
set sashelp.heart;
run;

proc summary data=have;
var weight;
output out=Q3 q3=q3;
run;

data want;
 set have;
 if _n_=1 then set q3(keep=q3);
 if weight>=q3 ;
 drop q3;
run;

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!

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
  • 575 views
  • 6 likes
  • 4 in conversation