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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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