BookmarkSubscribeRSS Feed
abhim701
Calcite | Level 5

I am trying to use Rank function on a numeric variable num_var to get a new variable num_var_1 with ranks. In my output I get the new variable num_var_1 with ranks 0,2,3,4,5,6,7,8,9.    Rank 1 is missing.

 

proc rank data = source_data out = output groups =10 ties = low;
var num_var.;
ranks num_var_1;
run;

 

What could be the possible reason for this?

Thanks in advance for help.

 

Regards

Abhishek

6 REPLIES 6
PGStats
Opal | Level 21

There must be a large number of ties at the minimum value, more than 20% of your data. Ties=low will give rank 0 to those obs.

PG
abhim701
Calcite | Level 5

Thanks for the help! I got it now.

abhim701
Calcite | Level 5

I tried ties = high. This also gives me the same output.

0,2,3,4,5,6,7,8,9.

 

I was expecting 

1,2,3,4,5,6,7,8,9

 

any comments?

 

 

PGStats
Opal | Level 21

Can't say without seeing the data. One way to break the ties is to add a small random component to the data:

 

data source_data_rnd;
set source_data;
num_var_rnd = num_var + rand("UNIFORM")*0.00001;
run;

proc rank data = source_data_rnd out=output(drop=num_var_rnd) groups=10;
var num_var_rnd;
ranks num_var_1;
run;
PG
Ksharp
Super User
Try
 ties = dense

Rick_SAS
SAS Super FREQ

 For a discussion of some common reasons this could happen, see the article "Binning data by quantiles."

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 3717 views
  • 1 like
  • 4 in conversation