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."

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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