%macro setall(libref,pattern,patstart=1,setopts=); /* --see the much more efficient and elegant allsets.sas module in /mscdc/sascode-- */ /*--macro to generate a list of set statments to access all datasets in a sdl that contain value &pattern in their name beginning at byte &patstart. Result is stored as value of global variable &_allsets. You first invoke the macro (between SAS steps) and then code your reference. e.g: %setall(stf3,mo) data modata; set &_allsets; .... The set statement references all datasets in library stf with names beginning with "mo". If pattern is null as well, then it selects ALL members without a filter. */ %*--jgb, 4-23-96--; %*--mods to add if stmt parm and allow all-sets processing 9-9-96--; %*--mod 1-97 to use proc contents out datasets instead of sashelp.vtable; %global _nsets; %global _allsets; %put ***setall macro begin execution***; proc contents data=&libref.._all_ noprint out=_contout(keep=memname); proc sort data=_contout out=_memnams nodupkeys; by memname; run; data _allsets; *** set sashelp.vtable(keep=libname memname memtype nobs); *** where libname=upcase("&libref"); set _memnams; %if %quote(&pattern) ne %str() %then %str( if substr(memname,&patstart) =: upcase("&pattern"); ); length nsets 4; nsets+1; length setvar $8 setval $17; setvar='set'||left(put(nsets,5.)); setval="&libref.."||memname; call symput(setvar,setval); call symput('nsets',nsets); run; %put nsets= &nsets; %let _allsets=; %do iset=1 %to &nsets; %let _allsets=&_allsets &&&set&iset ; %if %quote(&setopts) ne %str() %then %do; %let _allsets=&_allsets(&setopts) ; %end; %end; %put You may now reference the global variable _allsets with value; %put &_allsets; %mend setall;