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!
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!
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!
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.
Okay, now I understand! Thanks so much! @Reeza
@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.
Thanks so much! @PaigeMiller
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;
PROC UNIVARIATE, PROC MEANS and PROC SUMMARY will compute the 25th percentile, the 75th percentile and many other percentiles upon request.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.