I'm looking to create a column that contains the word 3 words before and 3 words directly after a keyword in my target column "Apple Description" For example, if the keyword I would like to search for is "Apple" then The market has apples and alot of bananas ==> column 1 ->> "The market has" . column 2 ->> " and alot of " I love to eat a lot of apples ==> "a lot of" I like orange juice ==> "" And I would like to apply that to multiple keywords like "apple" or "apple like" or "apple fruit" altogether. Thanks! CF data want;
length before after $200;
string="a b c d e trigger f g h i j";
do i=1 to countw(string," ");
if scan(string,i," ")="trigger" then do;
before=scan(string,i-5," ");
after=scan(string,i+5," ");
before2=scan(string,i-4," ");
after2=scan(string,i+4," ");
end;
end;
run;
... View more