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

I have a variable called 'Contact Name'. In this variable there are staff names and ID.

Contact name will have values of staff members name (both first name and surname, but sometimes just first name and sometimes no name)  and ID, 3 character and 3 numeric eg 

John Smith ABC123

Peter DEF345

Harry (GHI678)

Harry GHI678

 

What I'd like to do, is that when the ID does not have brackets around them, I'd like to have brackets around them.

 

Current State: Harry GHI678

Desired outcome: Harry (GHI678)

 

Cheers

Haydn

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

Please try the perl regular expression as below

 

data have;
input name&$50.;
cards;
John Smith ABC123
Peter DEF345
Harry (GHI678)
Harry GHI678
;

data want;
set have;
new=prxchange('s/(.*)(\w{3}\d{3})$/$1($2)/oi',-1,strip(name));
run;
Thanks,
Jag

View solution in original post

1 REPLY 1
Jagadishkatam
Amethyst | Level 16

Please try the perl regular expression as below

 

data have;
input name&$50.;
cards;
John Smith ABC123
Peter DEF345
Harry (GHI678)
Harry GHI678
;

data want;
set have;
new=prxchange('s/(.*)(\w{3}\d{3})$/$1($2)/oi',-1,strip(name));
run;
Thanks,
Jag

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
  • 1 reply
  • 457 views
  • 1 like
  • 2 in conversation