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 !!!
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
;
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
;
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
;
Thank you!
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!
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.