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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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

 

View solution in original post

3 REPLIES 3
art297
Opal | Level 21

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

 

Reeza
Super User

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.

 

 

Ksharp
Super User
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;

sas-innovate-2024.png

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.

 

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
  • 3 replies
  • 693 views
  • 0 likes
  • 4 in conversation