BookmarkSubscribeRSS Feed
hdg
Obsidian | Level 7 hdg
Obsidian | Level 7

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!


3 REPLIES 3
data_null__
Jade | Level 19
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;
data cluster;
   set cluster;
   by date cluster_id;
   if first.date then new_id = 0;
  
if first.cluster_id then new_id + 1;
  
run;
proc print;
  
run;
Astounding
PROC Star

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;

yaswanthj
Calcite | Level 5

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

sas-innovate-2024.png

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.

 

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
  • 3 replies
  • 902 views
  • 0 likes
  • 4 in conversation