From 1062a97cfecf67577e78dc2428c7facf5fcf7e18 Mon Sep 17 00:00:00 2001 From: munja Date: Fri, 24 Dec 2021 22:02:23 +0000 Subject: [PATCH] feat: new validation (ISINT) in the mp_validatecol.sas macro - https://core.sasjs.io/mp__validatecol_8sas_source.html --- all.sas | 14 ++++++++- base/mp_validatecol.sas | 14 ++++++++- tests/crossplatform/mp_validatecol.test.sas | 34 +++++++++++++++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/all.sas b/all.sas index dc736a6..921f8ea 100644 --- a/all.sas +++ b/all.sas @@ -9892,10 +9892,13 @@ alter table &libds modify &var char(&len); ;;;; run; + For more examples, see mp_validatecol.test.sas + Tip - when contributing, use https://regex101.com to test the regex validity! @param [in] incol The column to be validated @param [in] rule The rule to apply. Current rules: + @li ISINT - checks if the variable is an integer @li ISNUM - checks if the variable is numeric @li LIBDS - matches LIBREF.DATASET format @li FORMAT - checks if the provided format is syntactically valid @@ -9904,6 +9907,9 @@ alter table &libds modify &var char(&len);

SAS Macros

@li mf_getuniquename.sas +

Related Macros

+ @li mp_validatecol.test.sas + @version 9.3 **/ @@ -9913,7 +9919,13 @@ alter table &libds modify &var char(&len); %local tempcol; %let tempcol=%mf_getuniquename(); -%if &rule=ISNUM %then %do; +%if &rule=ISINT %then %do; + &tempcol=input(&incol,?? best32.); + &outcol=0; + if not missing(&tempcol) then if mod(&incol,1)=0 then &outcol=1; + drop &tempcol; +%end; +%else %if &rule=ISNUM %then %do; /* credit SØREN LASSEN https://sasmacro.blogspot.com/2009/06/welcome-isnum-macro.html diff --git a/base/mp_validatecol.sas b/base/mp_validatecol.sas index bef24e7..ae25cca 100644 --- a/base/mp_validatecol.sas +++ b/base/mp_validatecol.sas @@ -20,10 +20,13 @@ ;;;; run; + For more examples, see mp_validatecol.test.sas + Tip - when contributing, use https://regex101.com to test the regex validity! @param [in] incol The column to be validated @param [in] rule The rule to apply. Current rules: + @li ISINT - checks if the variable is an integer @li ISNUM - checks if the variable is numeric @li LIBDS - matches LIBREF.DATASET format @li FORMAT - checks if the provided format is syntactically valid @@ -32,6 +35,9 @@

SAS Macros

@li mf_getuniquename.sas +

Related Macros

+ @li mp_validatecol.test.sas + @version 9.3 **/ @@ -41,7 +47,13 @@ %local tempcol; %let tempcol=%mf_getuniquename(); -%if &rule=ISNUM %then %do; +%if &rule=ISINT %then %do; + &tempcol=input(&incol,?? best32.); + &outcol=0; + if not missing(&tempcol) then if mod(&incol,1)=0 then &outcol=1; + drop &tempcol; +%end; +%else %if &rule=ISNUM %then %do; /* credit SØREN LASSEN https://sasmacro.blogspot.com/2009/06/welcome-isnum-macro.html diff --git a/tests/crossplatform/mp_validatecol.test.sas b/tests/crossplatform/mp_validatecol.test.sas index 2fdae62..64c66a9 100644 --- a/tests/crossplatform/mp_validatecol.test.sas +++ b/tests/crossplatform/mp_validatecol.test.sas @@ -92,4 +92,38 @@ run; desc=Test3 - ISFORMAT, test=EQUALS 5, outds=work.test_results +) + +/** + * Test 4 - ISINT + */ +data test4; + infile datalines4 dsd; + input; + infile=_infile_; + %mp_validatecol(infile,ISINT,is_integer) + if is_integer=1; +datalines4; +1 +1234 +-134 +-1.0 +1.0 +0 +above are good +the rest are bad +%abort +1&somethingverybad. +& ++-1 +. +a.A +$format12.1b +$format12.1b1 +;;;; +run; +%mp_assertdsobs(work.test4, + desc=Test4 - ISFORMAT, + test=EQUALS 6, + outds=work.test_results ) \ No newline at end of file