BookmarkSubscribeRSS Feed
Shayan2012
Quartz | Level 8

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!

1 REPLY 1
Scott_Mitchell
Quartz | Level 8

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;

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1 reply
  • 825 views
  • 1 like
  • 2 in conversation