Macro findvars

From sasCommunity
Jump to: navigation, search

Macros_by_Ian_Whitlock

%macro findvars ( lib = , vlist = ) ;
options nolabel mprint;
 
%let vlist = %upcase ( &vlist );
 
data __vars ( keep = name ) ;
     length name $ 32 ;
do i = 1 to 200 
   until( scan( "&vlist" , i ) = ' ' );
   name = scan ( "&vlist" , i ) ;
   if name ^= ' ' then output __vars ;
   end ;
run;
 
proc sql; select f.name 
                 , v.memname 
                 , count( distinct v.memname ) as found
            from __vars as f 
                 left join
         (select memname 
                ,name
            from dictionary.columns
           where libname = upcase("&lib") 
             and memtype = 'DATA' 
             and " &vlist " contains ' '||trim(name)||' '
         ) as v
          on       f.name = v.name
          group by f.name
          order by f.name, v.memname;
          quit;
options label;
%mend  findvars;

harvesting and code polishing by:

--macro maven == the radical programmer 13:21, 23 May 2012 (EDT)