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!
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.