/* libname macro by John Blodgett, OSEDA, U of Missouri. This macro generates a libname stmt for a "filetype" on the data archive. If the filetype (subdirectory) does not exist, then the libname statement is issued and a NOTE: message is written to the SAS log telling you that the library does not exist. Samples: Invocation Generates this code =========== ====================================== %libname(stf803) libname stf803 '/pub/data/census_1980/stf803' access=readonly; %libname(stf904,b) libname stf904b '/pub/data/census_1990/stf904/b' access=readonly; %libname(popests,mohealth) libname mohealth '/pub/data/popests/mohealth' access=readonly; %libname(corrlst,libref=sasnew,opts=) libname sasnew '/pub/data/corrlst'; The opts parm is used to specify, by default, that you want to access the library in read-only mode. If you need write access, either do not use this macro or override the opts parm as in: %libname(stf803x,opts=) ; libref generated is normally same as filetype, but if subdir is specfied, then we use it as the libref, unless the combined length of filetype and subdir is <= 8, in which case we concatenate. Useful for stf904 and a. */ %macro libname(filetype,subdir,basedir=%str(/pub/data),libref=,engine=,opts=%str(access=readonly)); %if %quote(&libref) eq %str() %then %do; %if %quote(&subdir) eq %str() %then %let libref = &filetype; %else %do; %let lconcat = %eval(%length(&filetype) + %length(&subdir); %if %eval(&lconcat) le 8 %then %let libref = &filetype.&subdir; %else %let libref = &subdir; %end; %end; %if &subdir ne %then %let subdir = &filetype%quote(/)&subdir; %else %let subdir = &filetype; libname &libref "&basedir/&subdir" &opts; %mend libname;