An update for anyone that comes across this thread. Modules 1 and 2 (in the main program) work and the issue I was having related to Macro parameters. In this instance I had incorrectly structured the input parameters in the Macro program (wrong spot). A correction of this can be seen in the code below. This was only realised thanks to the first author of the program. I encourage anyone with an interest in this thread to read A simple approach to text analysis using SAS functions’ Paper 2557-2018 from the 2018 SAS Global Forum (The code in this thread was developed by the authors of this paper and is explained in it) being an incredibly insightful and relevant paper and contribution. %MACRO KW_SEARCH(KW=, Var_KW_in=, Var_KW_out=, Data_IN=, Data_OUT=, Var_Target_Doc=);
DATA &Data_OUT Replace;
ATTRIB Flag_success length=3;
KW= UPCASE(&KW);
SET &Data_IN;
Target_string=UPCASE(COMPBL(TRANSLATE(&Var_Target_Doc, " " , ".%,;:?!-/\")));
KW_words = COUNTW(KW);
N_words = COUNTW(Target_string);
ARRAY word {1:1000} $50 _TEMPORARY_ ;
ARRAY IdW {1:100} _TEMPORARY_ ;
ARRAY Idx {1:100} _TEMPORARY_ ;
ARRAY Sdx {1:100} _TEMPORARY_ ;
Soundex_Count=0; Index_count=0; IndexW_count=0;
DO i=1 TO (N_words);
word(i)=SCAN( Target_string, i, ' ' );
IF i GE(KW_words) THEN DO;
length Target_truncated $50;
Target_truncated='';
DO j=1 TO KW_words;
Target_truncated= UPCASE(STRIP(CATX(" ", word(i-j+1) ,Target_truncated)));
END;
END;
IF (INDEXW(Target_truncated, STRIP(KW))>0) THEN IdW(i)=1; ELSE IdW(i)=0;
IF (INDEX(COMPRESS(Target_truncated), COMPRESS(KW))>0) THEN Idx(i) =1; ELSE Idx(i) =0;
IF (INDEX(SOUNDEX(Target_truncated), SOUNDEX(KW))>0) THEN Sdx(i) =1; ELSE Sdx(i) =0;
IndexW_count=IndexW_count + IdW(i);
Index_count=Index_count + Idx(i);
Soundex_Count=Soundex_Count + Sdx(i);
END;
IF (Certainty_factor=1) AND (IndexW_count>0) THEN DO;
&Var_KW_out=IndexW_count; END;
IF (Certainty_factor=2) AND ((Index_count-IndexW_count)>0) THEN DO;
&Var_KW_out=(Index_count-IndexW_count); END;
IF (Certainty_factor=3) AND ((Soundex_Count-IndexW_count)>0) THEN DO;
&Var_KW_out=(Soundex_Count-IndexW_count); END;
IF &Var_KW_out>0 THEN Flag_success=1;
DROP i j KW KW_words N_words Soundex_Count Index_count IndexW_count Target_truncated Target_string;
%MEND;
%MACRO CERTAINTY_FACTOR ( Data_OUT=, Data_IN=);
DATA &Data_OUT;
SET &Data_IN;
DO Certainty_factor=1 to 3;
OUTPUT;
END;
%MEND;
... View more