From 436b430389387108c1ddf5333446b19898acc3fb Mon Sep 17 00:00:00 2001 From: munja Date: Wed, 22 Dec 2021 11:23:57 +0000 Subject: [PATCH] feat: mf_islibds() macro to test if a library.dataset reference is syntactically valid --- base/mf_islibds.sas | 40 +++++++++++++++++++++ tests/crossplatform/mf_islibds.test.sas | 46 +++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 base/mf_islibds.sas create mode 100644 tests/crossplatform/mf_islibds.test.sas diff --git a/base/mf_islibds.sas b/base/mf_islibds.sas new file mode 100644 index 0000000..28e65f2 --- /dev/null +++ b/base/mf_islibds.sas @@ -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 + +

Related Macros

+ @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; \ No newline at end of file diff --git a/tests/crossplatform/mf_islibds.test.sas b/tests/crossplatform/mf_islibds.test.sas new file mode 100644 index 0000000..3f6d401 --- /dev/null +++ b/tests/crossplatform/mf_islibds.test.sas @@ -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; + +

SAS Macros

+ @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 +)