Please help! I want to Rank the second variable in this code.
data have;
input id region;
datalines;
10 US
10 CA
10 CA
23 MA
25 MA
45 Ks
50 US
50 SA
65 US
;
proc sort data = have;
by id;
run;
data want;
set have;
by id;
if first.id then rank =1;
else rank+1;
run;
Output needed:
ID Rank1 Rank2
10 1 1
10 2 1
10 3 2
https://stats.idre.ucla.edu/sas/faq/how-can-i-create-an-enumeration-variable-by-groups/
Instructions above for the various situations you're working with.
What is your rule for ranking a character variable?
Since you have US within 3 of the ID groups it isn't clear what that rule may be.
Also you might want to work the result for all of your example data and not remove the Region variable.
Thank you, My rule is to Rank a new column when the variable is US, Another Column to Rank, for CA separately and one column with no rules.(which I already got it from the prev query)
https://stats.idre.ucla.edu/sas/faq/how-can-i-create-an-enumeration-variable-by-groups/
Instructions above for the various situations you're working with.
Thank you Reeza!.. Great article! It helps!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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 lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.