38%macro mf_getuniquefileref(prefix=_,maxtries=1000,lrecl=32767);
40 %
if &prefix=0 %then %
do;
41 %let rc=%sysfunc(filename(fname,,temp,lrecl=&lrecl));
42 %
if &rc %then %put %sysfunc(sysmsg());
47 %let len=%eval(8-%length(&prefix));
49 %
do x=0 %to &maxtries;
50 %let fname=&prefix%substr(%sysfunc(ranuni(0)),3,&len);
51 %
if %sysfunc(fileref(&fname)) > 0 %then %
do;
52 %let rc=%sysfunc(filename(fname,,temp,lrecl=&lrecl));
53 %
if &rc %then %put %sysfunc(sysmsg());
58 %put unable to find available fileref after &maxtries attempts;
60%mend mf_getuniquefileref;