Hi everyone
@Ksharp gave a great solusion to the probelm of extracting a sentence with keyword from a text:
data want;
set have;
pid=prxparse('/([^\.]|\.(?=\d))+\./o');
start=1;stop=length(string);
call prxnext(pid,start,stop,string,p,l);
do while(p>0);
found=substr(string,p,l);
if find(found,'keyword','i') then output;
call prxnext(pid,start,stop,string,p,l);
end;
run;
Out of interest, anyinw can suggest modification to this code to also extract the sentence before the one that containes the keyword?
Thanks
Managed to solve it !
data want;
set want_temp;
pid=prxparse('/([^\.]|\.(?=\d))+\./o');
start=1;stop=length(string);
call prxnext(pid,start,stop,string,p,l);
do while(p>0);
found=substr(string,p,l);
found2=substr(string,p2,l2);
if find(found,'keyword','i') then output;
p2=p; l2=l;
call prxnext(pid,start,stop,string,p,l);
end;
run;
Managed to solve it !
data want;
set want_temp;
pid=prxparse('/([^\.]|\.(?=\d))+\./o');
start=1;stop=length(string);
call prxnext(pid,start,stop,string,p,l);
do while(p>0);
found=substr(string,p,l);
found2=substr(string,p2,l2);
if find(found,'keyword','i') then output;
p2=p; l2=l;
call prxnext(pid,start,stop,string,p,l);
end;
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.