Hello-.
I have ID variable as such;
How can I take out the dashes (-) in the ID?
1 | 01-1-001 | 40 |
---|---|---|
2 | 01-1-001 | 40 |
3 | 01-1-001 | 40 |
4 | 01-1-001 | 40 |
5 | 01-1-002 | 29 |
6 | 01-1-002 | 29 |
7 | 01-1-002 | 29 |
To get rid of them:
ID = compress(ID, '-');
If you want to change them to blanks instead, use the TRANSLATE function instead of COMPRESS.
ID = translate(ID, ' ', '-');
To get rid of them:
ID = compress(ID, '-');
If you want to change them to blanks instead, use the TRANSLATE function instead of COMPRESS.
ID = translate(ID, ' ', '-');
Thanks you!
Alternatively, you can also try the perl regular expression
data want;
input id$;
id=prxchange('s/-//i',-1,id);
cards;
01-1-001
;
Hi @Jagadishkatam Appreciate your enthusiasm, however for this case(OP's requirement) I don't think PRX is an alternative. It is awfully slow when I tested with 40 million records. However, I like your thinking. PRX is better utilized for complex patterns as opposed to straight forward use of SAS functions such as this case.
Nonetheless, thank you for your contribution
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.