29%macro mf_getuniquelibref(prefix=mc,maxtries=1000);
32 %
if ( %length(&prefix) gt 7 ) %then %
do;
33 %put %str(ERR)OR: The prefix parameter cannot exceed 7 characters.;
37 %
else %
if (%sysfunc(NVALID(&prefix,v7))=0) %then %
do;
38 %put %str(ERR)OR: Invalid prefix (&prefix);
44 %let maxtries=%eval(10**(8-%length(&prefix))-1);
46 %
do x = 0 %to &maxtries;
47 %
if %sysfunc(libref(&prefix&x)) ne 0 %then %
do;
51 %let x = %eval(&x + 1);
54 %put %str(ERR)OR: No usable libref in range &prefix.0-&maxtries;
55 %put %str(ERR)OR- Try reducing the prefix or deleting some libraries!;
57%mend mf_getuniquelibref;