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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.