From 6587dce95bdf74ae653ed15bc31bc03283f10683 Mon Sep 17 00:00:00 2001 From: munja Date: Wed, 13 Jul 2022 23:57:02 +0100 Subject: [PATCH] feat: new mf_increment macro --- all.sas | 29 ++++++++++++++++++++++++++ base/mf_increment.sas | 29 ++++++++++++++++++++++++++ tests/base/mf_increment.test.sas | 35 ++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 base/mf_increment.sas create mode 100644 tests/base/mf_increment.test.sas diff --git a/all.sas b/all.sas index f8df375..54a070b 100644 --- a/all.sas +++ b/all.sas @@ -1598,6 +1598,35 @@ Usage: &engine %mend mf_getxengine; +/** + @file + @brief Increments a macro variable + @details Useful outside of do-loops - will increment a macro variable every + time it is called. + + Example: + + %let cnt=1; + %put We have run %mf_increment(cnt) lines; + %put Now we have run %mf_increment(cnt) lines; + %put There are %mf_increment(cnt) lines in total; + + @param [in] MACRO_NAME the name of the macro variable to increment + @param [in] ITER= The amount to add or subtract to the macro + +

Related Files

+ @li mf_increment.test.sas + +**/ + +%macro mf_increment(macro_name,incr=1); + + /* iterate the value */ + %let ¯o_name=%eval(&&¯o_name+&incr); + /* return the value */ + &&¯o_name + +%mend mf_increment; /** @file mf_isblank.sas @brief Checks whether a macro variable is empty (blank) diff --git a/base/mf_increment.sas b/base/mf_increment.sas new file mode 100644 index 0000000..eeb7ce1 --- /dev/null +++ b/base/mf_increment.sas @@ -0,0 +1,29 @@ +/** + @file + @brief Increments a macro variable + @details Useful outside of do-loops - will increment a macro variable every + time it is called. + + Example: + + %let cnt=1; + %put We have run %mf_increment(cnt) lines; + %put Now we have run %mf_increment(cnt) lines; + %put There are %mf_increment(cnt) lines in total; + + @param [in] MACRO_NAME the name of the macro variable to increment + @param [in] ITER= The amount to add or subtract to the macro + +

Related Files

+ @li mf_increment.test.sas + +**/ + +%macro mf_increment(macro_name,incr=1); + + /* iterate the value */ + %let ¯o_name=%eval(&&¯o_name+&incr); + /* return the value */ + &&¯o_name + +%mend mf_increment; diff --git a/tests/base/mf_increment.test.sas b/tests/base/mf_increment.test.sas new file mode 100644 index 0000000..ca3ad7e --- /dev/null +++ b/tests/base/mf_increment.test.sas @@ -0,0 +1,35 @@ +/** + @file + @brief Testing mf_increment macro + +

SAS Macros

+ @li mf_increment.sas + @li mp_assert.sas + +**/ + +%let var=0; + +%mp_assert( + iftrue=( + "%mf_increment(var)"="1" + ), + desc=Checking basic mf_increment usage 1, + outds=work.test_results +) + +%mp_assert( + iftrue=( + "%mf_increment(var)"="2" + ), + desc=Checking basic mf_increment usage 2, + outds=work.test_results +) + +%mp_assert( + iftrue=( + "%mf_increment(var,incr=2)"="4" + ), + desc=Checking incr option, + outds=work.test_results +)