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

Hi Team,

 

I would like to know, if is possible to select the word in a specific interval string.


Ex: Variable name: Comments
I need select the words between PROCESS ORIGIN  and FACTS.

 

 

PROCESS ORIGIN sas communities FACTS

PROCESS ORIGIN Google Inc FACTS

PROCESS ORIGIN Google FACTS

 

Thx !!!

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

 

data want(drop=_:);
  input string&$100.;
  length want $80;
  retain _re;

  if _n_=1 then
    _re=prxparse('/\bprocess origin\b(.*)\bfacts\b/oi');

  if prxmatch(_re, trim(string)) then
    do;
      want=prxposn(_re, 1, string);
    end;

  cards;
PROCESS ORIGIN sas communities FACTS
PROCESS ORIGIN Google Inc FACTS
PROCESS ORIGIN Google FACTS
Process Original Mix by Wehbba facts
blah PROCESS ORIGIN Google Inc FACTS
blah PROCESS ORIGIN Google Inc xxFACTS
blah PROCESS ORIGIN Google Inc FACTSxx
;

 

View solution in original post

3 REPLIES 3
Jagadishkatam
Amethyst | Level 16

Please try

 

data want;
input string&$100.;
want=prxchange('s/(.*origin)(.*)(FACTS\s)/$2/i',-1,string);
cards;
PROCESS ORIGIN sas communities FACTS
PROCESS ORIGIN Google Inc FACTS
PROCESS ORIGIN Google FACTS
;
Thanks,
Jag
Patrick
Opal | Level 21

 

data want(drop=_:);
  input string&$100.;
  length want $80;
  retain _re;

  if _n_=1 then
    _re=prxparse('/\bprocess origin\b(.*)\bfacts\b/oi');

  if prxmatch(_re, trim(string)) then
    do;
      want=prxposn(_re, 1, string);
    end;

  cards;
PROCESS ORIGIN sas communities FACTS
PROCESS ORIGIN Google Inc FACTS
PROCESS ORIGIN Google FACTS
Process Original Mix by Wehbba facts
blah PROCESS ORIGIN Google Inc FACTS
blah PROCESS ORIGIN Google Inc xxFACTS
blah PROCESS ORIGIN Google Inc FACTSxx
;

 

Sk1_SAS
Obsidian | Level 7

Thank you!

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 665 views
  • 0 likes
  • 3 in conversation