Hi,
I want to subset string between words 'user/utilisateur' and 'du/in' . Considering English and French both.
I have variable 'Description' with following values:
DECSRIPTION:
Attribué à utilisateur Ali Khan du groupe Quebec Property 2
Assigned to user Marie-Helene Adams in group CAS
Assigned to user Jeff Mills in group National Personal Lines Auto 3
Assigned to user Wendy Taylor-Wu in group NRU Auto/Casualty
Attribué à utilisateur Laurence A. Weinstein du groupe Quebec 1
What i want - variable Name with value:
Ali Khan
Marie-Helene Adams
Jeff Mills
Wendy Taylor-Wu
Laurence A. Weinstein
Thank you!
Here is one way:
data want (drop=start end);
set have;
if findw(DECSRIPTION,'user') then start=
findw(DECSRIPTION,'user') +5;
else start=findw(DECSRIPTION,'utilisateur') +12;
end=max(findw(DECSRIPTION,'du'),findw(DECSRIPTION,'in')) -1;
name=substr(DECSRIPTION,start,end-start);
run;
Art, CEO, AnalystFinder.com
Here is one way:
data want (drop=start end);
set have;
if findw(DECSRIPTION,'user') then start=
findw(DECSRIPTION,'user') +5;
else start=findw(DECSRIPTION,'utilisateur') +12;
end=max(findw(DECSRIPTION,'du'),findw(DECSRIPTION,'in')) -1;
name=substr(DECSRIPTION,start,end-start);
run;
Art, CEO, AnalystFinder.com
If all your data is this structured, use INDEXW to find the location of the words and that will give you the positions of the string you want to extract. Make sure to either upper case or lower case the comparisons.
data have;
input x $80.;
s=prxmatch('/utilisateur|user/',x);
e=prxmatch('/du groupe|in group/',x);
temp=substr(x,s,e-s);
want=substr(temp,findc(temp,' '));
drop s e temp;
cards;
Attribué à utilisateur Ali Khan du groupe Quebec Property 2
Assigned to user Marie-Helene Adams in group CAS
Assigned to user Jeff Mills in group National Personal Lines Auto 3
Assigned to user Wendy Taylor-Wu in group NRU Auto/Casualty
Attribué à utilisateur Laurence A. Weinstein du groupe Quebec 1
;
run;
proc print noobs;run;
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.