Chapter Contents

Previous

Next
%DATATYP

%DATATYP



Returns the data type of a value

Type: Autocall macro
Requires: 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 Institute. This library may not be installed at your site or may 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 SAS Software Consultant. For more information, see Chapter 9 in SAS Macro Language: Reference.  [cautionend]


Details

The DATATYP macro returns a value of NUMERIC when an argument consists of digits and, optionally, 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.


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.