Macro Functions |
Type: | Macro function |
See also: | %EVAL Function |
Syntax | |
Details | |
Comparisons | |
Example | |
Illustrating Floating-Point Evaluation |
Syntax |
%SYSEVALF(expression<, conversion-type>) |
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 one of the following:
0 if the result of the expression is 0 or missing | |
1 if the result is any other value. |
%sysevalf(1/3,boolean) /* returns 1 */ %sysevalf(10+.,boolean) /* returns 0 */
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:
%sysevalf(1 + 1.1,ceil) /* returns 3 */ %sysevalf(-1 -2.4,ceil) /* returns -3 */ %sysevalf(-1 + 1.e-11,ceil) /* returns 0 */ %sysevalf(10+.) /* returns . */
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 a missing value produces a missing value:
%sysevalf(-2.4,floor) /* returns -3 */ %sysevalf(3,floor) /* returns 3 */ %sysevalf(1.-1.e-13,floor) /* returns 1 */ %sysevalf(.,floor) /* returns . */
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 a missing value produces a missing value:
%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. Specify a conversion type to prevent problems when %SYSEVALF returns one of the following:
missing or floating-point values to macro expressions
macro variables that are used in other macro expressions that require an integer value
For details about evaluation of expressions by the SAS macro language, see Macro Expressions.
Comparisons |
%SYSEVALF supports floating-point numbers. However, %EVAL performs only integer arithmetic.
You must use the %SYSEVALF macro function in macros to evaluate floating-point expressions. However, %EVAL is used automatically by the macro processor to evaluate macro expressions.
Example |
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)
When this program executes, these lines are written 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
Copyright © 2009 by SAS Institute Inc., Cary, NC, USA. All rights reserved.