Help using Base SAS procedures

How to rank observations in an arbitrary way?

Reply
Frequent Contributor
Posts: 75

How to rank observations in an arbitrary way?

Hi All,

I am trying to rank observations based on a specific percent i.e. if the percentage is less than 10%, the observation belongs to rank 1; if less than 20% and more than 10% to rank 2, and so on. So, I cannot use proc rank in this case. I can write it with sql and case, like

case

when percent le .1 a

when percent gt .1 and percent le .2 b ; ...

but it seems to me that it is inefficient and there must be a better way.

Can anyone please let me know if there is a more straight way of doing this?

Thanks a lot!

Super Contributor
Posts: 297

Re: How to rank observations in an arbitrary way?

Posted in reply to Shayan2012

You could use proc format.

PROC FORMAT;

VALUE PERRANK

LOW  -< 0.1 = '1'

0.1  -< 0.2 = '2'

0.2  -< 0.3 = '3'

0.3  -< 0.4 = '4'

0.4  -< 0.5 = '5'

0.5  -< 0.6 = '6'

0.6  -< 0.7 = '7'

0.7  -< 0.8 = '8'

0.8  -< 0.9 = '9'

0.9  -< 1.0 = '10'

;

RUN;

DATA HAVE;

DO I = 1 TO 100000;

PERCENT = RANUNI(0);

OUTPUT;

END;

RUN;

DATA WANT;

SET HAVE;

RANK = PUT(PERCENT,PERRANK.);

RUN;

Ask a Question
Discussion stats
  • 1 reply
  • 142 views
  • 1 like
  • 2 in conversation