%macro xlists(/* This macro takes the name (NOT the values or references, the NAMEs) of three global macro variables - specified as positional parms. It looks at each word in the value of the 2nd parm to see if it can be matched in the value of the first (master) list. It executes a SAS data step which uses symput calls to define the result as the value of the macro variable specified as the 3rd parameter (which should be declared as global prior to invoking this macro). Messages are written to the log indicating the value of the new list and that of a second list containing all the words removed from the 2nd list. All words are based on using only blanks as delimiters. The master list is upcased for the purpose of checking and all words are upcased to see if they exist in the master list. So the idea is that the lists be case insensitive. J. Blodgett, OSEDA, last updated 2/6/2010 10:46:39 AM */ _list1,_list2,_listout,nolog=0); data _null_; retain list1 "&&&_list1" list2 "&&&_list2" listout "&&&_list1"; retain removed "&&&_list1"; *---idea is to take the intersection of the 2 lists and output it. list1 is the master and list2 is the selector. To be in output you must be in both lists.; if upcase(list1)=upcase(list2) then do; removed=' '; goto callsym; end; listout=' '; removed=' '; list1=upcase(list1); *<----new---; word=scan(list2,1,' '); i=1; do while (word ne ' '); if index(list1,trim(upcase(word))) then listout=trimn(listout)||' '||word; else removed=trimn(removed)||' '||word; i+1; word=scan(list2,i,' '); end; callsym: call symput("&_listout",trimn(listout)); %global xlists_removed; call symput('xlists_removed',trimn(removed)); %if &nolog=0 %then %do; file log; put 'xlists macro has assigned values as follows: ' / "&_listout" '=' listout '.' / 'xlists_removed=' removed '.'; %end; stop; run; %mend xlists;