1
0
mirror of https://github.com/sasjs/core.git synced 2025-12-11 06:24:35 +00:00

feat: mp_webin() macro for handling the _webin_xxx macro variables in SAS web services

This commit is contained in:
Allan Bowe
2021-09-08 19:34:28 +03:00
parent 6013897c50
commit 3f69cf506a
5 changed files with 244 additions and 39 deletions

View File

@@ -1,29 +1,39 @@
/**
@file
@brief Assigns and returns an unused fileref
@details
@details 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();
%let fileref2=%mf_getuniquefileref(prefix=0);
%put &fileref1 &fileref2;
which returns something similar to:
which returns filerefs similar to:
> #LN01295 #LN01297
> _7432233 #LN00070
A previous version of this macro worked by assigning sequential filerefs.
The current version uses the native "find a unique fileref" functionality
within the filename function, which is 100 times faster.
@param prefix= Deprecated. Will be removed in a future release.
@param maxtries= Deprecated. Will be removed in a future release.
@param [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.
@param [in] maxtries= (1000) the last part of the libref. Must be an integer.
@version 9.2
@author Allan Bowe
**/
%macro mf_getuniquefileref(prefix=0,maxtries=1000);
%macro mf_getuniquefileref(prefix=_,maxtries=1000);
%local rc fname;
%if &prefix=0 %then %do;
%let rc=%sysfunc(filename(fname,,temp));
@@ -31,17 +41,18 @@
&fname
%end;
%else %do;
%local x;
%local x len;
%let len=%eval(8-%length(&prefix));
%let x=0;
%do x=0 %to &maxtries;
%if %sysfunc(fileref(&prefix&x)) > 0 %then %do;
%let fname=&prefix&x;
%let rc=%sysfunc(filename(fname,,temp));
%if &rc %then %put %sysfunc(sysmsg());
&prefix&x
%return;
%let fname=&prefix%substr(%sysfunc(ranuni(0)),3,&len);
%if %sysfunc(fileref(&fname)) > 0 %then %do;
%let rc=%sysfunc(filename(fname,,temp));
%if &rc %then %put %sysfunc(sysmsg());
&fname
%return;
%end;
%end;
%end;
%put unable to find available fileref in range &prefix.0-&maxtries;
%put unable to find available fileref after &maxtries attempts;
%end;
%mend mf_getuniquefileref;