BookmarkSubscribeRSS Feed
asasha
Obsidian | Level 7

Hello, I need to rank a numeric variable into 5 groups by another categorical variable and also get the cutoffs. I currently have this code:

 

proc rank data=dsout out=ranks groups=5;
   by var2;
   var var1;
   ranks var1_rank;
run;

I have 2 columns now (var1, var2), and I want the output to be 4 columns. The var1 ranks by var2 (var1_rank) derived using the above code and the cutoff values (range) that would take a value like '0.0999254969 <= x1 < 0.1993986319' based on how the ranks are calculated. Thanks.

 

1 REPLY 1
Reeza
Super User
I don't think there's a good way to do this all in one step except a manual data step...curious to see other answers.

Assuming you don't want that, I'd use PROC RANKS and then pass the results to PROC MEANS and find the MIN/MAX for each RANK and merge that back into my output from PROC RANK.

Example of adding average value to a data set - modify it to return min/max instead of average.
https://github.com/statgeek/SAS-Tutorials/blob/master/add_average_value_to_dataset.sas

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1642 views
  • 1 like
  • 2 in conversation