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
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.