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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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