☑ This topic is solved.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 10-01-2022 01:32 PM
(795 views)
Hi, how can I add suffix to Ids based on a column?
Suppose to have:
Id suffix
0001 1
0001 1
0001 2
0002 2
0002 2
0002 1
Desired output
Id
0001_1
0001_1
0001_2
0002_2
0002_2
0002_1
Thank you in advance
Suppose to have:
Id suffix
0001 1
0001 1
0001 2
0002 2
0002 2
0002 1
Desired output
Id
0001_1
0001_1
0001_2
0002_2
0002_2
0002_1
Thank you in advance
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Most probably, you need to define a new variable (because of the length):
data want;
set have (rename=(id=_id)),
length id $6;
id = catx("_",_id,suffix);
drop _id suffix;
run;
4 REPLIES 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Most probably, you need to define a new variable (because of the length):
data want;
set have (rename=(id=_id)),
length id $6;
id = catx("_",_id,suffix);
drop _id suffix;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you dottor bremser. It works perfectly. Only one question: is it possible to convert back the modified ID to numeric?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I would not do that. Something that is not used for calculations, but for identification, is better kept as character.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
ok thank you! It is just because there is a piece of code downstream that looks at it as numeric.