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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.