mirror of
https://github.com/sasjs/core.git
synced 2026-01-14 12:00:05 +00:00
feat: new validation (ISINT) in the mp_validatecol.sas macro - https://core.sasjs.io/mp__validatecol_8sas_source.html
This commit is contained in:
14
all.sas
14
all.sas
@@ -9892,10 +9892,13 @@ alter table &libds modify &var char(&len);
|
|||||||
;;;;
|
;;;;
|
||||||
run;
|
run;
|
||||||
|
|
||||||
|
For more examples, see mp_validatecol.test.sas
|
||||||
|
|
||||||
Tip - when contributing, use https://regex101.com to test the regex validity!
|
Tip - when contributing, use https://regex101.com to test the regex validity!
|
||||||
|
|
||||||
@param [in] incol The column to be validated
|
@param [in] incol The column to be validated
|
||||||
@param [in] rule The rule to apply. Current rules:
|
@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 ISNUM - checks if the variable is numeric
|
||||||
@li LIBDS - matches LIBREF.DATASET format
|
@li LIBDS - matches LIBREF.DATASET format
|
||||||
@li FORMAT - checks if the provided format is syntactically valid
|
@li FORMAT - checks if the provided format is syntactically valid
|
||||||
@@ -9904,6 +9907,9 @@ alter table &libds modify &var char(&len);
|
|||||||
<h4> SAS Macros </h4>
|
<h4> SAS Macros </h4>
|
||||||
@li mf_getuniquename.sas
|
@li mf_getuniquename.sas
|
||||||
|
|
||||||
|
<h4> Related Macros </h4>
|
||||||
|
@li mp_validatecol.test.sas
|
||||||
|
|
||||||
@version 9.3
|
@version 9.3
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@@ -9913,7 +9919,13 @@ alter table &libds modify &var char(&len);
|
|||||||
%local tempcol;
|
%local tempcol;
|
||||||
%let tempcol=%mf_getuniquename();
|
%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
|
credit SØREN LASSEN
|
||||||
https://sasmacro.blogspot.com/2009/06/welcome-isnum-macro.html
|
https://sasmacro.blogspot.com/2009/06/welcome-isnum-macro.html
|
||||||
|
|||||||
@@ -20,10 +20,13 @@
|
|||||||
;;;;
|
;;;;
|
||||||
run;
|
run;
|
||||||
|
|
||||||
|
For more examples, see mp_validatecol.test.sas
|
||||||
|
|
||||||
Tip - when contributing, use https://regex101.com to test the regex validity!
|
Tip - when contributing, use https://regex101.com to test the regex validity!
|
||||||
|
|
||||||
@param [in] incol The column to be validated
|
@param [in] incol The column to be validated
|
||||||
@param [in] rule The rule to apply. Current rules:
|
@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 ISNUM - checks if the variable is numeric
|
||||||
@li LIBDS - matches LIBREF.DATASET format
|
@li LIBDS - matches LIBREF.DATASET format
|
||||||
@li FORMAT - checks if the provided format is syntactically valid
|
@li FORMAT - checks if the provided format is syntactically valid
|
||||||
@@ -32,6 +35,9 @@
|
|||||||
<h4> SAS Macros </h4>
|
<h4> SAS Macros </h4>
|
||||||
@li mf_getuniquename.sas
|
@li mf_getuniquename.sas
|
||||||
|
|
||||||
|
<h4> Related Macros </h4>
|
||||||
|
@li mp_validatecol.test.sas
|
||||||
|
|
||||||
@version 9.3
|
@version 9.3
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@@ -41,7 +47,13 @@
|
|||||||
%local tempcol;
|
%local tempcol;
|
||||||
%let tempcol=%mf_getuniquename();
|
%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
|
credit SØREN LASSEN
|
||||||
https://sasmacro.blogspot.com/2009/06/welcome-isnum-macro.html
|
https://sasmacro.blogspot.com/2009/06/welcome-isnum-macro.html
|
||||||
|
|||||||
@@ -93,3 +93,37 @@ run;
|
|||||||
test=EQUALS 5,
|
test=EQUALS 5,
|
||||||
outds=work.test_results
|
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
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user