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;
Thanks!
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.
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.
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.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.