From 459beff4fa93cb05755218ab4b96f8b39cc4a980 Mon Sep 17 00:00:00 2001 From: vrh Date: Thu, 3 Sep 2020 17:49:44 +0200 Subject: [PATCH] feat: mf_trimstr macro --- all.sas | 41 ++++++++++++++++++++++++++++++++++++++++- base/mf_getplatform.sas | 3 ++- base/mf_trimstr.sas | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 base/mf_trimstr.sas diff --git a/all.sas b/all.sas index 879f189..bc999ea 100644 --- a/all.sas +++ b/all.sas @@ -510,6 +510,7 @@ options noquotelenmax;

Dependencies

@li mf_mval.sas + @li mf_trimstr.sas @version 9.4 / 3.4 @author Allan Bowe @@ -555,7 +556,7 @@ options noquotelenmax; %else 0; %end; %else %if &switch=VIYARESTAPI %then %do; - %sysfunc(getoption(servicesbaseurl)) + %mf_trimstr(%sysfunc(getoption(servicesbaseurl)),/) %end; %mend;/** @file @@ -1290,6 +1291,44 @@ Usage: %macro mf_nobs(libds )/*/STORE SOURCE*/; %mf_getattrn(&libds,NLOBS) +%mend;/** + @file mf_trimstr.sas + @brief Removes character(s) from the end, if they exist + @details If the designated characters exist at the end of the string, they + are removed + + %put %mf_trimstr(/blah/,/); * /blah; + %put %mf_trimstr(/blah/,h); * /blah/; + %put %mf_trimstr(/blah/,h/); */bla; + +

Dependencies

+ + + @param basestr The string to be modified + @param trimstr The string to be removed from the end of `basestr`, if it exists + + @return output returns result with the value of `trimstr` removed from the end + + + @version 9.2 + @author Allan Bowe + +**/ + +%macro mf_trimstr(basestr,trimstr); +%local trimlen trimval; +%let trimlen=%length(%superq(trimstr)); +%let trimval=%qsubstr(%superq(basestr) + ,%length(%superq(basestr))-&trimlen+1 + ,&trimlen); + +%if %superq(trimval)=%superq(trimstr) %then %do; + %qsubstr(%superq(basestr),1,%length(%superq(basestr))-&trimlen) +%end; +%else %do; + &basestr +%end; + %mend;/** @file @brief Creates a Unique ID based on system time in a friendly format diff --git a/base/mf_getplatform.sas b/base/mf_getplatform.sas index 021fe66..5672074 100644 --- a/base/mf_getplatform.sas +++ b/base/mf_getplatform.sas @@ -12,6 +12,7 @@

Dependencies

@li mf_mval.sas + @li mf_trimstr.sas @version 9.4 / 3.4 @author Allan Bowe @@ -57,6 +58,6 @@ %else 0; %end; %else %if &switch=VIYARESTAPI %then %do; - %sysfunc(getoption(servicesbaseurl)) + %mf_trimstr(%sysfunc(getoption(servicesbaseurl)),/) %end; %mend; \ No newline at end of file diff --git a/base/mf_trimstr.sas b/base/mf_trimstr.sas new file mode 100644 index 0000000..18a8b52 --- /dev/null +++ b/base/mf_trimstr.sas @@ -0,0 +1,39 @@ +/** + @file mf_trimstr.sas + @brief Removes character(s) from the end, if they exist + @details If the designated characters exist at the end of the string, they + are removed + + %put %mf_trimstr(/blah/,/); * /blah; + %put %mf_trimstr(/blah/,h); * /blah/; + %put %mf_trimstr(/blah/,h/); */bla; + +

Dependencies

+ + + @param basestr The string to be modified + @param trimstr The string to be removed from the end of `basestr`, if it exists + + @return output returns result with the value of `trimstr` removed from the end + + + @version 9.2 + @author Allan Bowe + +**/ + +%macro mf_trimstr(basestr,trimstr); +%local trimlen trimval; +%let trimlen=%length(%superq(trimstr)); +%let trimval=%qsubstr(%superq(basestr) + ,%length(%superq(basestr))-&trimlen+1 + ,&trimlen); + +%if %superq(trimval)=%superq(trimstr) %then %do; + %qsubstr(%superq(basestr),1,%length(%superq(basestr))-&trimlen) +%end; +%else %do; + &basestr +%end; + +%mend; \ No newline at end of file