Published on :
Macro INTERNAL_CREATION

Using the %SYSEVALF Macro Function

This code is also available in: Deutsch Español Français
Awaiting validation
The main objective of this script is to present SAS©'s %SYSEVALF macro function. It initializes two macro variables, `&a` (integer) and `&b` (decimal number), then uses %SYSEVALF to perform an addition between these two values. The script highlights %SYSEVALF's ability to handle floating-point calculations, which %EVAL cannot do without generating an error. Additionally, it explores %SYSEVALF's conversion options: BOOLEAN, CEIL, FLOOR, and INTEGER, showing how the result can be adapted to different needs.
Data Analysis

Type : INTERNAL_CREATION


The data used (values of macro variables `a` and `b`) are created and defined directly within the SAS script.

1 Code Block
GLOBAL STATEMENT / MACRO STATEMENT Data
Explanation :
Activates the SYMBOLGEN option to display macro variable resolution in the log. Then defines two macro variables, `&a` as an integer and `&b` as a floating-point number, which will be used in subsequent calculations.
Copied!
1OPTIONS SYMBOLGEN;
2 
3%let a = 100;
4%let b = 1.59;
2 Code Block
MACRO FUNCTION
Explanation :
Calculates the sum of macro variables `&a` and `&b` using `%SYSEVALF`, which allows handling floating-point numbers without error. The result is stored in macro variable `&y`. Then, several `%PUT` statements display the base result and the results of specific `%SYSEVALF` conversions (BOOLEAN, CEIL, FLOOR, INTEGER), demonstrating how the function can modify the format and value of the result.
Copied!
1%let y = %sysevalf(&a+&b);
2 
3%put The RESULT with SYSEVALF is: &y;
4%put BOOLEAN conversion: %sysevalf(&a +&b, boolean);
5%put CEIL conversion: %sysevalf(&a +&b, ceil);
6%put FLOOR conversion: %sysevalf(&a +&b, floor);
7%put INTEGER conversion: %sysevalf(&a +&b, integer);
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : Educational source: Lesson 2.4: Using the %SYSEVAL Function, Lesson 2 - Using Macro Functions, SAS Macro Language 1: Essentials.