/******************************************************************** * NAME: setdir SYSTEM: MSCDC PGMR: BLODGETT * * FUNCTION: generate a sas set statement referencing all sas sets * * in a subdir. It writes the generated code to setall.sas in * * the directory specified by the path parm. A libref value equal* * to the last level of path is assumed, i.e. if a value of * * /mscdc/data/filetype is specified as the path parm then a * * libref of filetype is assumed. * * NOTES: Assumes unix environment. Issues a "x cd &path" stmt - * * changing the current directory. * * So by default writes to setall.sas in &path directory * ********************************************************************/ %GLOBAL REVDATE; %LET REVDATE=22feb96; *<----DATE OF LAST REVISION; /********************************************************************/ /* BEGIN MACRO DEFINITION */ /********************************************************************/ %MACRO setdir (path,sasout=%str(setall.sas)); /* path is a required postional parm: has the path name of the directory containing the datasets to be accessed. */ /* END */ /* Sample invocation: %setdir(%str(/mscdc/data/corrlst/plc2cnty)) This would result in the SAS source code file "setall.sas" being written to the directory specified by the value of the parm. If this directory contained the SAS datasets al, ar and az then the generated source code would be: set plc2cnty.al plc2cnty.ar plc2cnty.az ; This assumes that the program that uses this code will define the libref plc2cnty referencing this path. */ %PUT %STR( ); %PUT ***************************************************************; %put * setdir macro Rev &revdate begin execution *; %put * Missouri State Census Data Center *; %PUT ***************************************************************; %PUT %STR( ); x cd &path; %put **Notice that path has been chaned to &path; filename dirin pipe "ls *.ssd01"; filename sasout "&sasout"; data _null_; infile dirin end=last; length setname $17 libref $8; input setname $; _ix=index(setname,'.ssd01'); substr(setname,_ix)=' '; retain libref; file sasout lrecl=72; if _n_=1 then do; if index("&path",'/') then libref=reverse(scan(reverse("&path"),1,'/')); else libref="&path"; put '***generated set statement using setdir macro***'; put ' set '; end; length setref $17; setref=trim(libref)||"."||setname; put setref +1 @; if last then put / ';'; run; %MEND setdir;