mirror of
https://github.com/sasjs/core.git
synced 2026-06-08 20:10:20 +00:00
feat: new mfv_getcaslib macro
Fetches a caslib from a regular SAS libref
This commit is contained in:
@@ -0,0 +1,69 @@
|
|||||||
|
/**
|
||||||
|
@file
|
||||||
|
@brief Testing mfv_getcaslib macro function
|
||||||
|
|
||||||
|
<h4> SAS Macros </h4>
|
||||||
|
@li mfv_getcaslib.sas
|
||||||
|
@li mp_assert.sas
|
||||||
|
@li mp_assertscope.sas
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
options mprint;
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------ */
|
||||||
|
/* Setup: start a CAS session and assign caslibs */
|
||||||
|
/* ------------------------------------------------------------------------ */
|
||||||
|
cas mysess;
|
||||||
|
caslib _all_ assign;
|
||||||
|
|
||||||
|
%let testcaslib=Public;
|
||||||
|
|
||||||
|
libname castest cas caslib=&testcaslib;
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------ */
|
||||||
|
%put TEST 1 - returns the caslib name for a valid CAS libref;
|
||||||
|
/* ------------------------------------------------------------------------ */
|
||||||
|
%mp_assert(
|
||||||
|
iftrue=(%mfv_getcaslib(castest)=%upcase(&testcaslib)),
|
||||||
|
desc=Check correct caslib name returned for a valid CAS libref
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------ */
|
||||||
|
%put TEST 2 - returns empty for a non-CAS libref (WORK);
|
||||||
|
/* ------------------------------------------------------------------------ */
|
||||||
|
%mp_assert(
|
||||||
|
iftrue=(%mfv_getcaslib(WORK)=),
|
||||||
|
desc=Check empty string returned for a non-CAS libref
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------ */
|
||||||
|
%put TEST 3 - returns empty for a libref that does not exist;
|
||||||
|
/* ------------------------------------------------------------------------ */
|
||||||
|
%mp_assert(
|
||||||
|
iftrue=(%mfv_getcaslib(DOESNOTEXIST)=),
|
||||||
|
desc=Check empty string returned for a non-existent libref
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------ */
|
||||||
|
%put TEST 5 - no scope leakage into global macro variables;
|
||||||
|
/* ------------------------------------------------------------------------ */
|
||||||
|
%mp_assertscope(SNAPSHOT)
|
||||||
|
|
||||||
|
%let _rc=%mfv_getcaslib(castest);
|
||||||
|
|
||||||
|
%mp_assertscope(COMPARE,
|
||||||
|
desc=Check mfv_getcaslib does not leak macro variables into GLOBAL scope,
|
||||||
|
ignorelist=_RC
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------ */
|
||||||
|
/* Teardown */
|
||||||
|
/* ------------------------------------------------------------------------ */
|
||||||
|
cas mysess terminate;
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
/**
|
||||||
|
@file mfv_getcaslib.sas
|
||||||
|
@brief Returns the CAS caslib name for a given SAS libref
|
||||||
|
@details Pure macro function. Reads sashelp.vlibnam and returns
|
||||||
|
the sysvalue where sysname='Caslib' for the given libref. This
|
||||||
|
is useful when the caslib name and libref name may differ.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
%put %mfv_getcaslib(lib=PUBLIC);
|
||||||
|
|
||||||
|
@param [in] lib SAS libref for which to return the CAS caslib name
|
||||||
|
|
||||||
|
@return Returns the CAS caslib name, or empty string if not found
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
%macro mfv_getcaslib(lib);
|
||||||
|
|
||||||
|
%local dsid rc result;
|
||||||
|
|
||||||
|
%let dsid=%sysfunc(open(sashelp.vlibnam(
|
||||||
|
where=(libname="%upcase(&lib)" and sysname="Caslib")
|
||||||
|
)));
|
||||||
|
|
||||||
|
%if &dsid %then %do;
|
||||||
|
%let rc=%sysfunc(fetch(&dsid));
|
||||||
|
%if &rc=0 %then
|
||||||
|
%let result=%sysfunc(
|
||||||
|
getvarc(&dsid,%sysfunc(varnum(&dsid,SYSVALUE)))
|
||||||
|
);
|
||||||
|
%let rc=%sysfunc(close(&dsid));
|
||||||
|
%end;
|
||||||
|
|
||||||
|
&result
|
||||||
|
|
||||||
|
%mend mfv_getcaslib;
|
||||||
Reference in New Issue
Block a user