This searches a string from left to right for two words, if they are in the string you will get the first position. If you need to search from right to add B or b to the 'e' in the findw parameters 'be' or 'eb' will search from the right. E or e says to report words instead of characters.
data example;
str="I'm not going to try to retype information provided in a picture. Looking for the word classify with AAA a number of words from it";
ClassifyWord= findw(str,'classify',' .,','e');
AAAWord = findw(str,'AAA',' .,','e');
if classifyword and AAAword then distance= abs(classifyword-AAAword);
run;
You could create arrays to hold 1) the first set of words to find, 2) the resulting position, 3) the second set of words to find, 4) there poisitions, 5) and possibly an array of the various possible distances combinations. You will have to come up with rules for how to ignore matches.
.
... View more