I have a reorder question
I have a cluster set say below
date cluster_id code
05/31/2000 1 A
05/31/2000 1 B
05/31/2000 3 C
05/31/2000 3 E
05/31/2000 5 F
05/31/2001 1 A
05/31/2001 2 B
05/31/2001 5 C
05/31/2001 7D
05/31/2001 7 E
05/31/2001 7 F
I would like to change the cluster id so that its numbered according to numeric order; everything else stays the same barring the cluster id
So for example the final set
05/31/2000 1 A
05/31/2000 1 B
05/31/2000 2 C
05/31/2000 2 E
05/31/2000 3 F
05/31/2001 1 A
05/31/2001 2 B
05/31/2001 3 C
05/31/2001 4 D
05/31/2001 4 E
05/31/2001 4 F
Thank you all for your help in advance!
Perhaps this way:
data want;
set have;
by date cluster_id;
if first.date then new_cluster_id = 1;
else if first.cluster_id then new_cluster_id + 1;
run;
Hi HDG..
We can do this using proc rank very easily ..here is the code for you..this may help for your requirement..
data cluster;
input date:mmddyy. cluster_id code:$1.;
format date mmddyy10.;
cards;
05/31/2000 1 A
05/31/2000 1 B
05/31/2000 3 C
05/31/2000 3 E
05/31/2000 5 F
05/31/2001 1 A
05/31/2001 2 B
05/31/2001 5 C
05/31/2001 7 D
05/31/2001 7 E
05/31/2001 7 F
;;;;
run;
proc print;
run;
proc rank data = cluster ties = dense out = want;
by date;
var cluster_id;
ranks clstr_wnt;
run;
proc print data = want;
run;
Thanks,
Yash...
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.