HI I realise there is a small issue with the code and I modified below:
data want;
retain terms;
length terms $32767;
set troy;
by source_key_value1;
if first.source_key_value1 then
terms='';
if not findw(terms,trim(upcase(term))) then
terms=catx(' ', upcase(terms), upcase(term));
if last.source_key_value1 then
do i=1 to countw(upcase(upcase(terms)),' ');
do j=1 to countw(upcase(terms),' ');
term1 =scan(upcase(terms), i);
term2 =scan(upcase(terms), j);
dist =999999;
pos1 =0;
pos2 =0;
do until(pos1=0 or pos2=0);
pos1=find(compress(msg1),trim(upcase(term1)),pos1+1);
if upcase(term1)=upcase(term2) then
pos2=pos1;
pos2=find(compress(msg1),trim(upcase(term2)),pos2+1);
if pos1 & pos2 then
dist=min(dist,abs(pos2-pos1));
end;
output;
end;
end;
run;
... View more