%macro swmatch(s1,s2,casematters=0,wordsonly=0); %*--Utility macro to examine two macro variables ("strings") with the purpose of checking to see if each word in string 1 (1st arg) is contained in string 2 (2nd arg). The two lists are assumed to be blank-delimited (no commas or other special characters allowed). The casematters flag parm can be used to specify (passing casematters=1) that case matters when checking for a match. By default it does not matter. Macro returns a single blank if all words in s1 are matched in s2. Otherwise it returns a blank-delimited string of word numbers and words that were not matched (separating the word number and word value with a colon). Unless wordsonly=1 is specified in which case it only returns the list of unmatched words with the number and the colon. Examples: s1=yes no maybe s2=yes and no Returns: 3:maybe s1=now is the time s2=now might be a good time Returns: 2:is 3:the s1= s2=any set of words Returns: (if s1 is blank always returns a blank) jgb, 10/7/2009 9:16:16 AM --*; %local null; %local _s1 _s2; %if &casematters %then %do; %let _s1=&s1; %let _s2=&s2; %end; %else %do; %let _s1=%lowcase(&s1); %let _s2=%lowcase(&s2); %end; %local allmatch i1 word1; %let allmatch=1; %let i1=1; %let word1=%scan(&_s1,1); %do %while(%nrbquote(&word1) ne &null); %if %sysfunc(indexw(&_s2,&word1))=0 %then %do; %let allmatch=0; %if &wordsonly %then %str(&word1 ); %else %str(&i1.:&word1 ); %end; %let i1=%eval(&i1+1); %let word1=%scan(&_s1,&i1); %end; %if &allmatch %then %str( ); %mend swmatch;