Chapter Contents

Previous

Next
%SYSEVALF

%SYSEVALF



Evaluates arithmetic and logical expressions using floating-point arithmetic

Type: Macro function
See also: %EVAL


Syntax
Details
Comparisons
Example
Illustrating Floating-Point Evaluation

Syntax

%SYSEVALF(expression<,conversion-type>)

expression
is an arithmetic or logical expression to evaluate

conversion-type
optionally converts the value returned by %SYSEVALF to the type of value specified. The value can then be used in other expressions that require a value of that type. Conversion-type can be

BOOLEAN
returns
0 if the result of the expression is 0 or missing
1 if the result is any other value.

For example,

%sysevalf(1/3,boolean)      /* returns 1 */
%sysevalf(10+.,boolean)     /* returns 0 */

CEIL
returns a character value representing the smallest integer that is greater than or equal to the result of the expression. If the result is within 10--12 of an integer, the function returns a character value representing that integer. An expression containing a missing value returns a missing value along with a message noting that fact. For example,
%sysevalf(1 + 1.1,ceil)       /* returns  3 */
%sysevalf(-1 -2.4,ceil)       /* returns -3 */
%sysevalf(-1 + 1.e-11,ceil)   /* returns -1 */
%sysevalf(10+.)               /* returns  . */

FLOOR
returns a character value representing the largest integer that is less than or equal to the result of the expression. If the result is within 10--12 of an integer, the function returns that integer. An expression with an missing value produces a missing value. For example,
%sysevalf(-2.4,floor)         /* returns -3 */
%sysevalf(3,floor)            /* returns  3 */
%sysevalf(1.-1.e-13,floor)    /* returns  1 */
%sysevalf(.,floor)            /* returns  . */

INTEGER
returns a character value representing the integer portion of the result (truncates the decimal portion). If the result of the expression is within 10--12 of an integer, the function produces a character value representing that integer. If the result of the expression is positive, INTEGER returns the same result as FLOOR. If the result of the expression is negative, INTEGER returns the same result as CEIL. An expression with an missing value produces a missing value. For example,
%put %sysevalf(2.1,integer);        /* returns  2 */
%put %sysevalf(-2.4,integer);       /* returns -2 */
%put %sysevalf(3,integer);          /* returns  3 */
%put %sysevalf(-1.6,integer);       /* returns -1 */
%put %sysevalf(1.-1.e-13,integer);  /* returns  1 */


Details

The %SYSEVALF function performs floating-point arithmetic and returns a value that is formatted using the BEST32. format. The result of the evaluation is always text. %SYSEVALF is the only macro function that can evaluate logical expressions that contain floating point or missing values. Specifying a conversion type can prevent problems when %SYSEVALF returns missing or floating point values to macro expressions or macro variables that are used in other macro expressions that require an integer value.

For details on evaluation of expressions by the SAS macro language, see Chapter 6 in SAS Macro Language: Reference.


Comparisons


Example

Example 1: Illustrating Floating-Point Evaluation

The macro FIGUREIT performs all types of conversions for SYSEVALF values.

%macro figureit(a,b);
   %let y=%sysevalf(&a+&b);
   %put The result with SYSEVALF is: &y;
   %put  The BOOLEAN value is: %sysevalf(&a +&b, boolean);
   %put  The CEIL value is: %sysevalf(&a +&b, ceil);
   %put  The FLOOR value is: %sysevalf(&a +&b, floor);
   %put  The INTEGER value is: %sysevalf(&a +&b, int);
%mend figureit;

%figureit(100,1.597)

Executing this program writes these lines to the SAS log:

The result with SYSEVALF is: 101.597
The BOOLEAN value is: 1
The CEIL value is: 102
The FLOOR value is: 101
The INTEGER value is: 101


Chapter Contents

Previous

Next

Top of Page

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