BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
stodo53
Fluorite | Level 6

Hi all,

 

I am working with repeated measures data, and I am trying to create a new unique ID that begins with 9999 for each new patient. If the patient is repeated, I still want them to have the same ID identifier. 

 

HAVE

 

 

WANT

 

OBS

ID

 

OBS

ID

1

4CTH101

 

1

9999001

2

4CTH101

 

2

9999001

3

4CTH102

 

3

9999002

4

4CTH102

 

4

9999002

5

4CTH104

 

5

9999004

6

4CTH105

 

6

9999005

 

I tried this but it creates a unique ID for each new observation. I think I need to integrate my ID variable but not sure how. 

DATA new; SET old;
	id2 = cats(9999,put(_n_,z3.));
RUN;

stodo53_1-1720434122686.png

 

Thanks!

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Why isn't there a 9999003 in your WANT data set?

 

If you data is sorted by ID, this should work:

 

data want;
     set have;
     by id;
     if first.id then counter+1;
     id2 = cats('9999',put(counter,z3.));
run;

 

Note: more than 9999 distinct values of ID will cause this to fail.

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Why isn't there a 9999003 in your WANT data set?

 

If you data is sorted by ID, this should work:

 

data want;
     set have;
     by id;
     if first.id then counter+1;
     id2 = cats('9999',put(counter,z3.));
run;

 

Note: more than 9999 distinct values of ID will cause this to fail.

--
Paige Miller
stodo53
Fluorite | Level 6

That was a typo on my end - I was just trying to show an example of how it would look like. 

 

This worked! Thanks so much. 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 418 views
  • 3 likes
  • 2 in conversation