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