Quantcast
Channel: ListenData
Viewing all articles
Browse latest Browse all 425

SAS : PROC RANK

$
0
0
This tutorial explains how to calculate rank for one or more numeric variables.

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;
var Score;
ranks ranking;
run;
Notes :  

  1. The OUT option is used to store output of the rank procedure.
  2. The VAR option is used to specify numeric variable (s) for which you want to calculate rank
  3. The RANKS option tells SAS to name the rank variable
  4. By default, it calculates rank in ascending order.
Output

Reverse order of ranking (Descending)
proc rank data= temp descending out = result;
var Score;
ranks ranking;
run;
Percentile Ranking (Quartile Rank)
proc rank data= temp descending groups = 4 out = result;
var Score;
ranks ranking;
run;
Note : 
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;
  1. LOW - assigns the smallest of the corresponding ranks.
  2. HIGH - assigns the largest of the corresponding ranks.
  3. MEAN - assigns the mean of the corresponding ranks (Default Option).

Viewing all articles
Browse latest Browse all 425

Trending Articles