Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mf_getuniquefileref.sas File Reference

Assigns and returns an unused fileref. More...

Go to the source code of this file.

Detailed Description

Using the native approach for assigning filerefs fails as some procedures (such as proc http) do not recognise the temporary names (starting with a hash), returning a message such as:

‍ERROR 22-322: Expecting a name.

This macro works by attempting a random fileref (with a prefix), seeing if it is already assigned, and if not - returning the fileref.

If your process can accept filerefs with the hash (#) prefix, then set prefix=0 to revert to the native approach - which is significantly faster when there are a lot of filerefs in a session.

Use as follows:

%let fileref1=%mf_getuniquefileref();
%let fileref2=%mf_getuniquefileref(prefix=0);
%put &fileref1 &fileref2;

which returns filerefs similar to:

‍_7432233 #LN00070

Parameters
[in]prefix=(_) first part of fileref. Remember that filerefs can only be 8 characters, so a 7 letter prefix would mean maxtries should be 10. if using zero (0) as the prefix, a native assignment is used.
[in]maxtries=(1000) the last part of the libref. Must be an integer.
[in]lrecl=(32767) Provide a default lrecl with which to initialise the generated fileref.
Version
9.2
Author
Allan Bowe

Definition in file mf_getuniquefileref.sas.