Previous Page | Next Page

AutoCall Macros

%DATATYP Autocall Macro



Returns the data type of a value.
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]


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]


Example


Example 1: 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.

Previous Page | Next Page | Top of Page