1
0
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:
munja
2021-12-22 11:23:57 +00:00
parent 6667b91ced
commit 436b430389
2 changed files with 86 additions and 0 deletions

40
base/mf_islibds.sas Normal file
View 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(&regex,&libds))
%mend mf_islibds;

View 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
)