Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to derive a new colnum according to a given colnum in SAS?

I have two columns like this:

subject regnum
106001 2
106001 2
106001 2
106001 1
106001 1
106001 4
106001 4
106001 6
106001 6
106001 3
106001 3
106001 5
106001 5
106001 7
106001 7
106001 8

and I want a new colmun like this:

subject regnum regnum_new
106001 2 1
106001 2 1
106001 2 1
106001 1 2
106001 1 2
106001 4 3
106001 4 3
106001 6 4
106001 6 4
106001 3 5
106001 3 5
106001 5 6
106001 5 6
106001 7 7
106001 7 7
106001 8 8

How can I do this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

data have;
input subject regnum;
datalines;
106001 2
106001 2
106001 2
106001 1
106001 1
106001 4
106001 4
106001 6
106001 6
106001 3
106001 3
106001 5
106001 5
106001 7
106001 7
106001 8
;

data want;
   set have;
   by subject regnum notsorted;
   if first.regnum then regnum_new + 1;
   if first.subject then regnum_new = 1;
run;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading