mirror of
https://github.com/sasjs/core.git
synced 2026-01-16 04:50:05 +00:00
chore: update to mf_getuniquelibref.sas
This commit is contained in:
@@ -14,27 +14,36 @@
|
|||||||
|
|
||||||
> mclib3
|
> mclib3
|
||||||
|
|
||||||
@param prefix= first part of libref. Remember that librefs can only be 8 characters,
|
A blank value is returned if no usable libname is determined.
|
||||||
so a 7 letter prefix would mean that maxtries should be 10.
|
|
||||||
@param maxtries= the last part of the libref. Provide an integer value.
|
@param prefix= first part of the returned libref. As librefs can be as long as
|
||||||
|
8 characters, a maximum length of 7 characters is premitted for this prefix.
|
||||||
|
@param maxtries= Deprecated parameter. Remains here to ensure a non-breaking
|
||||||
|
change.
|
||||||
|
|
||||||
@version 9.2
|
@version 9.2
|
||||||
@author Allan Bowe
|
@author Allan Bowe
|
||||||
**/
|
**/
|
||||||
|
|
||||||
|
|
||||||
%macro mf_getuniquelibref(prefix=mclib,maxtries=1000);
|
%macro mf_getuniquelibref(prefix=mclib,maxtries=1000);
|
||||||
%local x libref;
|
%local x;
|
||||||
%let x=0;
|
|
||||||
%do x=0 %to &maxtries;
|
%if ( %length(&prefix) gt 7 ) %then %do;
|
||||||
%if %sysfunc(libref(&prefix&x)) ne 0 %then %do;
|
%put NOTE: The prefix parameter cannot exceed 7 characters.;
|
||||||
%let libref=&prefix&x;
|
|
||||||
%let rc=%sysfunc(libname(&libref,%sysfunc(pathname(work))));
|
|
||||||
%if &rc %then %put %sysfunc(sysmsg());
|
|
||||||
&prefix&x
|
|
||||||
%*put &sysmacroname: Libref &libref assigned as WORK and returned;
|
|
||||||
%return;
|
%return;
|
||||||
%end;
|
%end;
|
||||||
|
|
||||||
|
/* Set maxtries equal to '10 to the power of [unused characters] - 1' */
|
||||||
|
%let maxtries=%eval(10**(8-%length(&prefix))-1);
|
||||||
|
|
||||||
|
%do x = 0 %to &maxtries;
|
||||||
|
%if %sysfunc(libref(&prefix&x)) ne 0 %then %do;
|
||||||
|
&prefix&x
|
||||||
|
%return;
|
||||||
|
%end;
|
||||||
|
%let x = %eval(&x + 1);
|
||||||
%end;
|
%end;
|
||||||
%put unable to find available libref in range &prefix.0-&maxtries;
|
|
||||||
|
%put NOTE: Unable to find a usable libref in the range &prefix.0-&maxtries..;
|
||||||
|
%put NOTE: Change the prefix parameter.;
|
||||||
%mend mf_getuniquelibref;
|
%mend mf_getuniquelibref;
|
||||||
Reference in New Issue
Block a user