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

Hello,

 

I am trying to calculate the top 25% and bottom 25% for a change score variable. The top 25% indicates high increases in scores and the bottom 25% indicates smaller increases in scores. Is there a way to determine the top 25% of scores and the bottom 25% of scores using proc means or proc univariate in SAS?

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Use PROC RANK with GROUPS=4.

 

proc rank data=sashelp.cars groups=4 out=cars;
var mpg_city;
ranks mpg_city_rank;
run;

Haven't verified the code but the idea is there. 

 


@bnd wrote:

Hello,

 

I am trying to calculate the top 25% and bottom 25% for a change score variable. The top 25% indicates high increases in scores and the bottom 25% indicates smaller increases in scores. Is there a way to determine the top 25% of scores and the bottom 25% of scores using proc means or proc univariate in SAS?

 

Thanks!


 

View solution in original post

8 REPLIES 8
Reeza
Super User

Use PROC RANK with GROUPS=4.

 

proc rank data=sashelp.cars groups=4 out=cars;
var mpg_city;
ranks mpg_city_rank;
run;

Haven't verified the code but the idea is there. 

 


@bnd wrote:

Hello,

 

I am trying to calculate the top 25% and bottom 25% for a change score variable. The top 25% indicates high increases in scores and the bottom 25% indicates smaller increases in scores. Is there a way to determine the top 25% of scores and the bottom 25% of scores using proc means or proc univariate in SAS?

 

Thanks!


 

bnd
Fluorite | Level 6 bnd
Fluorite | Level 6

Thank you @Reeza! The proc rank procedure allowed me to group the variable into quartiles. But, how would I go about getting the actual top 25% of scores and the bottom 25% of scores once the scores are grouped into the four quartiles? Also, the groups start at 0 rather than 1. 

Reeza
Super User
Group=0 are your bottom 25% and Group=3 is your top 25%. Yes the groups start from 0 and go to 3, you can add one to it, if that helps you.
bnd
Fluorite | Level 6 bnd
Fluorite | Level 6

Okay, now I understand! Thanks so much! @Reeza 

PaigeMiller
Diamond | Level 26

@bnd wrote:

But, how would I go about getting the actual top 25% of scores and the bottom 25% of scores once the scores are grouped into the four quartiles?


PROC UNIVARIATE, PROC MEANS or PROC SUMMARY will calculate these percentiles.

--
Paige Miller
bnd
Fluorite | Level 6 bnd
Fluorite | Level 6

Thanks so much! @PaigeMiller 

ballardw
Super User

The report procedures Tabulate and Report as well will do some percentiles. An example of calculating P25 and P75 for 3 variables, horsepower mpg_city and weight grouped by 3 categories, type drivetrain and number of cylinders from the SASHELP.CARS data.

 

proc tabulate data=sashelp.cars;
   class type  drivetrain cylinders;
   var horsepower mpg_city weight;
   table type  drivetrain cylinders,
         (horsepower mpg_city) *(p25 p75)
   ;
run;
PaigeMiller
Diamond | Level 26

PROC UNIVARIATE, PROC MEANS and PROC SUMMARY will compute the 25th percentile, the 75th percentile and many other percentiles upon request.

--
Paige Miller

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 8 replies
  • 2268 views
  • 0 likes
  • 4 in conversation