| AutoCall Macros |
| Type: | Autocall macro |
| Requirement: | MAUTOSOURCE system option |
| Syntax | |
| Details | |
| Example | |
| Determining the Data Type of a Value | |
Syntax |
| %DATATYP (text | text expression) |
Note: Autocall macros are included in a library supplied
by SAS. This library might not be installed at your site or might be a site-specific
version. If you cannot access this macro or if you want to find out if it
is a site-specific version, see your on-site SAS support personnel. ![[cautionend]](../../../../common/63294/HTML/default/images/cautend.gif)
| Details |
The DATATYP macro returns a value of NUMERIC when an argument consists of digits and a leading plus or minus sign, a decimal, or a scientific or floating-point exponent (E or D in uppercase or lowercase letters). Otherwise, it returns the value CHAR .
Note: %DATATYP does not identify hexadecimal
numbers. ![[cautionend]](../../../../common/63294/HTML/default/images/cautend.gif)
| Example |
%macro add(a,b); %if (%datatyp(&a)=NUMERIC and %datatyp(&b)=NUMERIC) %then %do; %put The result is %sysevalf(&a+&b).; %end; %else %do; %put Error: Addition requires numbers.; %end; %mend add;
You can invoke the ADD macro as:
%add(5.1E2,225)
The macro then writes this message to the SAS log:
The result is 735.
Similarly, you can invoke the ADD macro as:
%add(0c1x, 12)
The macro then writes this message to the SAS log:
Error: Addition requires numbers.
Copyright © 2009 by SAS Institute Inc., Cary, NC, USA. All rights reserved.