What if you have more than one occurence of a given term in your string? If you want to sum the scores for all occurrences, and you want to check for whole words only, something like this may be a possibility: filename tempsas temp;
data _null_;
set textscores;
file tempsas;
put "'" text $upcase. "'=" score;
run;
proc format;
invalue score
%include tempsas;
other=0;
run;
data score;
set textdata;
start=1;
pos=0;
len=0;
score=0;
do until(0);
call scan(substr(text,start),1,pos,len);
if pos=0 then leave;
start=start+pos-1;
score=score+input(substr(text,start,len),score.);
start=start+len;
if start>=vlength(text) then leave;
end;
run;
I used CALL SCAN on a substring, because that seems to work a lot faster than using the SCAN function with an increasing index.
... View more