BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
desireatem
Pyrite | Level 9

Hello-.

 

I have ID variable as such;

How can I take out the dashes (-) in the ID?

             ID                Age
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
   
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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, ' ', '-');

View solution in original post

4 REPLIES 4
Astounding
PROC Star

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, ' ', '-');

desireatem
Pyrite | Level 9

Thanks you!

Jagadishkatam
Amethyst | Level 16

Alternatively, you can also try the perl regular expression

 

data want;
input id$;
id=prxchange('s/-//i',-1,id);
cards;
01-1-001
;
Thanks,
Jag
Andygray
Quartz | Level 8

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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 3638 views
  • 2 likes
  • 4 in conversation