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!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.