Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mf_isint.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Returns 1 if the variable contains only digits 0-9, else 0
4 @details Note that numerics containing any punctuation (including decimals
5 or exponents) will be flagged zero.
6
7 If you'd like support for this, then do raise an issue (or even better, a
8 pull request!)
9
10 Usage:
11
12 %put %mf_isint(1) returns 1;
13 %put %mf_isint(1.1) returns 0;
14 %put %mf_isint(%str(1,1)) returns 0;
15
16 @param [in] arg input value to check
17
18 @version 9.2
19**/
20
21%macro mf_isint(arg
22)/*/STORE SOURCE*/;
23
24 /* blank val is not an integer */
25 %if "&arg"="" %then %do;0%return;%end;
26
27 /* remove minus sign if exists */
28 %local val;
29 %if "%substr(%str(&arg),1,1)"="-" %then %let val=%substr(%str(&arg),2);
30 %else %let val=&arg;
31
32 /* check remaining chars */
33 %if %sysfunc(findc(%str(&val),,kd)) %then %do;0%end;
34 %else %do;1%end;
35
36%mend mf_isint;