%DATATYP Autocall Macro

Returns the data type of a value.
Type: Autocall macro
Restriction: 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.
Requirement: MAUTOSOURCE system option

Syntax

%DATATYP (text | text expression)

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.

Example: Determining the Data Type of a Value

%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.