mirror of
https://github.com/sasjs/core.git
synced 2025-12-10 14:04:36 +00:00
feat: mf_islibds() macro to test if a library.dataset reference is syntactically valid
This commit is contained in:
40
base/mf_islibds.sas
Normal file
40
base/mf_islibds.sas
Normal file
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
@file
|
||||
@brief Checks whether a string follows correct library.dataset format
|
||||
@details Many macros in the core library accept a library.dataset parameter
|
||||
referred to as 'libds'. This macro validates the structure of that parameter,
|
||||
eg:
|
||||
|
||||
@li 8 character libref?
|
||||
@li 32 character dataset?
|
||||
@li contains a period?
|
||||
|
||||
It does NOT check whether the dataset exists, or if the library is assigned.
|
||||
|
||||
Usage:
|
||||
|
||||
%put %mf_islibds(work.something)=1;
|
||||
%put %mf_islibds(nolib)=0;
|
||||
%put %mf_islibds(badlibref.ds)=0;
|
||||
%put %mf_islibds(w.t.f)=0;
|
||||
|
||||
@param [in] libds The string to be checked
|
||||
|
||||
@return output Returns 1 if libds is valid, 0 if it is not
|
||||
|
||||
<h4> Related Macros </h4>
|
||||
@li mf_islibds.test.sas
|
||||
@li mp_validatecol.sas
|
||||
|
||||
@version 9.2
|
||||
**/
|
||||
|
||||
%macro mf_islibds(libds
|
||||
)/*/STORE SOURCE*/;
|
||||
|
||||
%local regex;
|
||||
%let regex=%sysfunc(prxparse(%str(/^[_a-z]\w{0,7}\.[_a-z]\w{0,31}$/i)));
|
||||
|
||||
%sysfunc(prxmatch(®ex,&libds))
|
||||
|
||||
%mend mf_islibds;
|
||||
46
tests/crossplatform/mf_islibds.test.sas
Normal file
46
tests/crossplatform/mf_islibds.test.sas
Normal file
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
@file
|
||||
@brief Testing mf_islibds macro
|
||||
|
||||
%put %mf_islibds(work.something)=1;
|
||||
%put %mf_islibds(nolib)=0;
|
||||
%put %mf_islibds(badlibref.ds)=0;
|
||||
%put %mf_islibds(w.t.f)=0;
|
||||
|
||||
<h4> SAS Macros </h4>
|
||||
@li mf_islibds.sas
|
||||
@li mp_assert.sas
|
||||
|
||||
**/
|
||||
|
||||
%mp_assert(
|
||||
iftrue=(
|
||||
%mf_islibds(work.something)=1
|
||||
),
|
||||
desc=%str(Checking mf_islibds(work.something)=1),
|
||||
outds=work.test_results
|
||||
)
|
||||
|
||||
%mp_assert(
|
||||
iftrue=(
|
||||
%mf_islibds(nolib)=0
|
||||
),
|
||||
desc=%str(Checking mf_islibds(nolib)=0),
|
||||
outds=work.test_results
|
||||
)
|
||||
|
||||
%mp_assert(
|
||||
iftrue=(
|
||||
%mf_islibds(badlibref.ds)=0
|
||||
),
|
||||
desc=%str(Checking mf_islibds(badlibref.ds)=0),
|
||||
outds=work.test_results
|
||||
)
|
||||
|
||||
%mp_assert(
|
||||
iftrue=(
|
||||
%mf_islibds(w.t.f)=0
|
||||
),
|
||||
desc=%str(Checking mf_islibds(w.t.f)=0),
|
||||
outds=work.test_results
|
||||
)
|
||||
Reference in New Issue
Block a user