DATA Step, Macro, Functions and more

Rank function missing few ranks

Reply
Occasional Contributor
Posts: 5

Rank function missing few ranks

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

Respected Advisor
Posts: 4,930

Re: Rank function missing few ranks

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
Occasional Contributor
Posts: 5

Re: Rank function missing few ranks

Thanks for the help! I got it now.

Occasional Contributor
Posts: 5

Re: Rank function missing few ranks

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?

 

 

Respected Advisor
Posts: 4,930

Re: Rank function missing few ranks

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
Super User
Posts: 10,044

Re: Rank function missing few ranks

Try
 ties = dense

SAS Super FREQ
Posts: 3,755

Re: Rank function missing few ranks

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

Ask a Question
Discussion stats
  • 6 replies
  • 414 views
  • 1 like
  • 4 in conversation