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;
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.