This tutorial explains how to calculate rank for one or more numeric variables.
Create Sample Data
Compute rank of numeric variable - "Score"
Create Sample Data
data temp;
input ID Gender $ Score;
cards;
1M33
2M94
3M66
4M46
5F92
6F95
7F18
8F11
;
run;
Compute rank of numeric variable - "Score"
proc rank data= temp out = result;Notes :
var Score;
ranks ranking;
run;
- The OUT option is used to store output of the rank procedure.
- The VAR option is used to specify numeric variable (s) for which you want to calculate rank
- The RANKS option tells SAS to name the rank variable
- By default, it calculates rank in ascending order.
Reverse order of ranking (Descending)
Ranking within BY group (Gender)
How to compute ranks for same values
Specify option TIES = HIGH | LOW | MEAN | DENSE in PROC RANK.
proc rank data= temp descending out = result;Percentile Ranking (Quartile Rank)
var Score;
ranks ranking;
run;
proc rank data= temp descending groups = 4 out = result;Note :
var Score;
ranks ranking;
run;
GROUPS=4 for quartile ranks, and GROUPS=10 for decile ranks, GROUPS = 100 for percentile ranks.
Ranking within BY group (Gender)
proc sort data = temp;
by gender;
run;
proc rank data= temp descending out = result;
var Score;
ranks ranking;
by Gender;
run;
How to compute ranks for same values
Specify option TIES = HIGH | LOW | MEAN | DENSE in PROC RANK.
proc rank data= temp descending ties = low out = result;
var Score;
ranks ranking;
run;
- LOW - assigns the smallest of the corresponding ranks.
- HIGH - assigns the largest of the corresponding ranks.
- MEAN - assigns the mean of the corresponding ranks (Default Option).