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
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.
Thanks for the help! I got it now.
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?
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;
Try ties = dense
For a discussion of some common reasons this could happen, see the article "Binning data by quantiles."
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.