From bf7459bd2d6e15ae160eaa973a39d90a6b2fbb6b Mon Sep 17 00:00:00 2001 From: Allan Bowe Date: Sat, 7 May 2022 17:45:36 +0000 Subject: [PATCH 1/5] feat: mf_dttm macro and associated test --- base/mf_dttm.sas | 29 ++++++++++++++++++++++++++++ tests/crossplatform/mf_dttm.test.sas | 22 +++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 base/mf_dttm.sas create mode 100644 tests/crossplatform/mf_dttm.test.sas diff --git a/base/mf_dttm.sas b/base/mf_dttm.sas new file mode 100644 index 0000000..a577bba --- /dev/null +++ b/base/mf_dttm.sas @@ -0,0 +1,29 @@ +/** + @file + @brief Returns E8601DT26.6 if compatible else DATETIME19.3 + @details Per our experience in [Data Controller for SAS] + (https://datacontroller.io) deployments, the E8601DT26.6 datetime format has + the widest support when it comes to pass-through SQL queries. + + However, it is not supported in WPS or early versions of SAS 9 (M3 and below). + + +

Related Macros

+ @li mf_dttm.test.sas + + @author Allan Bowe +**/ + +%macro mf_dttm( +)/*/STORE SOURCE*/; + +%if "&sysver"="9.2" or "&sysver"="9.3" + or ("&sysver"="9.4" and "%substr(&SYSVLONG,9,1)" le "3") + or "%substr(&sysver,1,1)"="4" + or "%substr(&sysver,1,1)"="5" +%then %do;DATETIME19.3%end; +%else %do;E8601DT26.6%end; + +%mend mf_dttm; + + diff --git a/tests/crossplatform/mf_dttm.test.sas b/tests/crossplatform/mf_dttm.test.sas new file mode 100644 index 0000000..d1fbf7a --- /dev/null +++ b/tests/crossplatform/mf_dttm.test.sas @@ -0,0 +1,22 @@ +/** + @file + @brief Testing mf_dttm macro + +

SAS Macros

+ @li mf_dttm.sas + @li mp_assert.sas + @li mp_assertscope.sas + +**/ + +%global test1; + +%mp_assertscope(SNAPSHOT) +%let test1=%mf_dttm(); +%mp_assertscope(COMPARE,ignorelist=test1) + +%mp_assert( + iftrue=("&test1"="DATETIME19.3" or "&test1"="E8601DT26.6"), + desc=Basic test, + outds=work.test_results +) From 1b013fbf1cac00e95f53904b4feccbc48144828c Mon Sep 17 00:00:00 2001 From: Allan Bowe Date: Sat, 7 May 2022 17:49:06 +0000 Subject: [PATCH 2/5] fix: rename to mf_fmtdttm() --- base/{mf_dttm.sas => mf_fmtdttm.sas} | 9 +++++---- .../{mf_dttm.test.sas => mf_fmtdttm.test.sas} | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) rename base/{mf_dttm.sas => mf_fmtdttm.sas} (74%) rename tests/crossplatform/{mf_dttm.test.sas => mf_fmtdttm.test.sas} (83%) diff --git a/base/mf_dttm.sas b/base/mf_fmtdttm.sas similarity index 74% rename from base/mf_dttm.sas rename to base/mf_fmtdttm.sas index a577bba..477c0f3 100644 --- a/base/mf_dttm.sas +++ b/base/mf_fmtdttm.sas @@ -1,20 +1,21 @@ /** @file @brief Returns E8601DT26.6 if compatible else DATETIME19.3 - @details Per our experience in [Data Controller for SAS] + @details From our experience in [Data Controller for SAS] (https://datacontroller.io) deployments, the E8601DT26.6 datetime format has the widest support when it comes to pass-through SQL queries. However, it is not supported in WPS or early versions of SAS 9 (M3 and below). + This macro will therefore return the appropriate format based on the runtime.

Related Macros

- @li mf_dttm.test.sas + @li mf_fmtdttm.test.sas @author Allan Bowe **/ -%macro mf_dttm( +%macro mf_fmtdttm( )/*/STORE SOURCE*/; %if "&sysver"="9.2" or "&sysver"="9.3" @@ -24,6 +25,6 @@ %then %do;DATETIME19.3%end; %else %do;E8601DT26.6%end; -%mend mf_dttm; +%mend mf_fmtdttm; diff --git a/tests/crossplatform/mf_dttm.test.sas b/tests/crossplatform/mf_fmtdttm.test.sas similarity index 83% rename from tests/crossplatform/mf_dttm.test.sas rename to tests/crossplatform/mf_fmtdttm.test.sas index d1fbf7a..e73548c 100644 --- a/tests/crossplatform/mf_dttm.test.sas +++ b/tests/crossplatform/mf_fmtdttm.test.sas @@ -1,6 +1,6 @@ /** @file - @brief Testing mf_dttm macro + @brief Testing mf_fmtdttm macro

SAS Macros

@li mf_dttm.sas @@ -12,7 +12,7 @@ %global test1; %mp_assertscope(SNAPSHOT) -%let test1=%mf_dttm(); +%let test1=%mf_fmtdttm(); %mp_assertscope(COMPARE,ignorelist=test1) %mp_assert( From 4b450f209120c7dd0ee6ebb7cd8d6023704f0c73 Mon Sep 17 00:00:00 2001 From: Allan Bowe Date: Sat, 7 May 2022 18:02:00 +0000 Subject: [PATCH 3/5] fix: implementation of mf_fmtddtm() --- base/mf_fmtdttm.sas | 16 ++++++++++++++-- base/mp_lockanytable.sas | 7 ++++--- base/mp_retainedkey.sas | 5 +++-- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/base/mf_fmtdttm.sas b/base/mf_fmtdttm.sas index 477c0f3..1cd1aeb 100644 --- a/base/mf_fmtdttm.sas +++ b/base/mf_fmtdttm.sas @@ -5,9 +5,21 @@ (https://datacontroller.io) deployments, the E8601DT26.6 datetime format has the widest support when it comes to pass-through SQL queries. - However, it is not supported in WPS or early versions of SAS 9 (M3 and below). + However, it is not supported in WPS or early versions of SAS 9 (M3 and below) + when used as a datetime literal, eg: - This macro will therefore return the appropriate format based on the runtime. + data _null_; + demo="%sysfunc(datetime(),E8601DT26.6)"dt; + demo=; + run; + + This macro will therefore return DATEITME19.3 as an alternative format + based on the runtime environment so that it can be used in such cases, eg: + + data _null_; + demo="%sysfunc(datetime(),%mf_fmtdttm())"dt; + demo=; + run;

Related Macros

@li mf_fmtdttm.test.sas diff --git a/base/mp_lockanytable.sas b/base/mp_lockanytable.sas index 40ce710..aa8c3ff 100644 --- a/base/mp_lockanytable.sas +++ b/base/mp_lockanytable.sas @@ -22,6 +22,7 @@ @param [in] loop_secs= (1) Seconds to wait between each lock attempt

SAS Macros

+ @li mf_fmtdttm.sas @li mp_abort.sas @li mp_lockfilecheck.sas @li mf_getuser.sas @@ -111,7 +112,7 @@ run; LOCK_LIB ="&lib"; LOCK_DS="&ds"; LOCK_STATUS_CD='LOCKED'; - LOCK_START_DTTM="%sysfunc(datetime(),E8601DT26.6)"dt; + LOCK_START_DTTM="%sysfunc(datetime(),%mf_fmtdttm())"dt; LOCK_USER_NM="&user"; LOCK_PID="&sysjobid"; LOCK_REF="&ref"; @@ -131,7 +132,7 @@ run; proc sql; update &ctl_ds set LOCK_STATUS_CD='LOCKED' - , LOCK_START_DTTM="%sysfunc(datetime(),E8601DT26.6)"dt + , LOCK_START_DTTM="%sysfunc(datetime(),%mf_fmtdttm())"dt , LOCK_USER_NM="&user" , LOCK_PID="&sysjobid" , LOCK_REF="&ref" @@ -206,7 +207,7 @@ run; proc sql; update &ctl_ds set LOCK_STATUS_CD='UNLOCKED' - , LOCK_END_DTTM="%sysfunc(datetime(),E8601DT26.6)"dt + , LOCK_END_DTTM="%sysfunc(datetime(),%mf_fmtdttm())"dt , LOCK_USER_NM="&user" , LOCK_PID="&sysjobid" , LOCK_REF="&ref" diff --git a/base/mp_retainedkey.sas b/base/mp_retainedkey.sas index 8d183bd..bcebada 100644 --- a/base/mp_retainedkey.sas +++ b/base/mp_retainedkey.sas @@ -58,6 +58,7 @@

SAS Macros

@li mf_existvar.sas + @li mf_fmtdttm.sas @li mf_getquotedstr.sas @li mf_getuniquename.sas @li mf_nobs.sas @@ -217,12 +218,12 @@ quit; set keytable="&base_libds" ,keycolumn="&retained_key" ,max_key=%eval(&maxkey+&newkey_cnt) - ,processed_dttm="%sysfunc(datetime(),E8601DT26.6)"dt; + ,processed_dttm="%sysfunc(datetime(),%mf_fmtdttm())"dt; %end; %else %do; update &maxkeytable set max_key=%eval(&maxkey+&newkey_cnt) - ,processed_dttm="%sysfunc(datetime(),E8601DT26.6)"dt + ,processed_dttm="%sysfunc(datetime(),%mf_fmtdttm())"dt where keytable="&base_libds"; %end; %mp_lockanytable(UNLOCK From 380170d5bacd4edec3f90e27c290bd1f97911be2 Mon Sep 17 00:00:00 2001 From: Allan Bowe Date: Sat, 7 May 2022 18:02:16 +0000 Subject: [PATCH 4/5] chore: all.sas --- all.sas | 54 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/all.sas b/all.sas index e8a1427..b02ecc0 100644 --- a/all.sas +++ b/all.sas @@ -369,6 +369,48 @@ https://github.com/yabwon/SAS_PACKAGES/blob/main/packages/baseplus.md#functionex %mend mf_existvarlist; /** @endcond *//** + @file + @brief Returns E8601DT26.6 if compatible else DATETIME19.3 + @details From our experience in [Data Controller for SAS] + (https://datacontroller.io) deployments, the E8601DT26.6 datetime format has + the widest support when it comes to pass-through SQL queries. + + However, it is not supported in WPS or early versions of SAS 9 (M3 and below) + when used as a datetime literal, eg: + + data _null_; + demo="%sysfunc(datetime(),E8601DT26.6)"dt; + demo=; + run; + + This macro will therefore return DATEITME19.3 as an alternative format + based on the runtime environment so that it can be used in such cases, eg: + + data _null_; + demo="%sysfunc(datetime(),%mf_fmtdttm())"dt; + demo=; + run; + +

Related Macros

+ @li mf_fmtdttm.test.sas + + @author Allan Bowe +**/ + +%macro mf_fmtdttm( +)/*/STORE SOURCE*/; + +%if "&sysver"="9.2" or "&sysver"="9.3" + or ("&sysver"="9.4" and "%substr(&SYSVLONG,9,1)" le "3") + or "%substr(&sysver,1,1)"="4" + or "%substr(&sysver,1,1)"="5" +%then %do;DATETIME19.3%end; +%else %do;E8601DT26.6%end; + +%mend mf_fmtdttm; + + +/** @file @brief Returns the appLoc from the _program variable @details When working with SASjs apps, web services / tests / jobs are always @@ -9259,6 +9301,7 @@ options ibufsize=&ibufsize; @param [in] loop_secs= (1) Seconds to wait between each lock attempt

SAS Macros

+ @li mf_fmtdttm.sas @li mp_abort.sas @li mp_lockfilecheck.sas @li mf_getuser.sas @@ -9348,7 +9391,7 @@ run; LOCK_LIB ="&lib"; LOCK_DS="&ds"; LOCK_STATUS_CD='LOCKED'; - LOCK_START_DTTM="%sysfunc(datetime(),E8601DT26.6)"dt; + LOCK_START_DTTM="%sysfunc(datetime(),%mf_fmtdttm())"dt; LOCK_USER_NM="&user"; LOCK_PID="&sysjobid"; LOCK_REF="&ref"; @@ -9368,7 +9411,7 @@ run; proc sql; update &ctl_ds set LOCK_STATUS_CD='LOCKED' - , LOCK_START_DTTM="%sysfunc(datetime(),E8601DT26.6)"dt + , LOCK_START_DTTM="%sysfunc(datetime(),%mf_fmtdttm())"dt , LOCK_USER_NM="&user" , LOCK_PID="&sysjobid" , LOCK_REF="&ref" @@ -9443,7 +9486,7 @@ run; proc sql; update &ctl_ds set LOCK_STATUS_CD='UNLOCKED' - , LOCK_END_DTTM="%sysfunc(datetime(),E8601DT26.6)"dt + , LOCK_END_DTTM="%sysfunc(datetime(),%mf_fmtdttm())"dt , LOCK_USER_NM="&user" , LOCK_PID="&sysjobid" , LOCK_REF="&ref" @@ -10232,6 +10275,7 @@ run;

SAS Macros

@li mf_existvar.sas + @li mf_fmtdttm.sas @li mf_getquotedstr.sas @li mf_getuniquename.sas @li mf_nobs.sas @@ -10391,12 +10435,12 @@ quit; set keytable="&base_libds" ,keycolumn="&retained_key" ,max_key=%eval(&maxkey+&newkey_cnt) - ,processed_dttm="%sysfunc(datetime(),E8601DT26.6)"dt; + ,processed_dttm="%sysfunc(datetime(),%mf_fmtdttm())"dt; %end; %else %do; update &maxkeytable set max_key=%eval(&maxkey+&newkey_cnt) - ,processed_dttm="%sysfunc(datetime(),E8601DT26.6)"dt + ,processed_dttm="%sysfunc(datetime(),%mf_fmtdttm())"dt where keytable="&base_libds"; %end; %mp_lockanytable(UNLOCK From 9d60c49c9f91185005375be4a1553ece5b6eedfb Mon Sep 17 00:00:00 2001 From: Allan Bowe Date: Sat, 7 May 2022 18:04:28 +0000 Subject: [PATCH 5/5] chore: incorrect dependency --- tests/crossplatform/mf_fmtdttm.test.sas | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/crossplatform/mf_fmtdttm.test.sas b/tests/crossplatform/mf_fmtdttm.test.sas index e73548c..9a3ca57 100644 --- a/tests/crossplatform/mf_fmtdttm.test.sas +++ b/tests/crossplatform/mf_fmtdttm.test.sas @@ -3,7 +3,7 @@ @brief Testing mf_fmtdttm macro

SAS Macros

- @li mf_dttm.sas + @li mf_fmtdttm.sas @li mp_assert.sas @li mp_assertscope.sas