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
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;
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.