Using% eval is sufficient if only integer arithmetic is required. If you need to perform floating point arithmetic with macro variables, you should use% sysevalf instead.
Most data step functions can be applied directly to macro variables using one of two methods:
1. %function() 2. %sysfunc(function())
For many of the most commonly used functions, there are exact macroequivalents, and all you have to do is add% before the function name. Functions that do not have exact macroequivalents can usually be taken to accept a macro variable by calling them inside% sysfunc (). Notably, however, they usually expect that a string enclosed in single quotes will fail when called in a piece of macro through% sysfunc () unless you remove the quotes. For example.
data _null_; x = rand('uniform'); run;
works fine in the data step, but in order to give a macro variable a single value in a piece of macro code, you will need to use
%let x = %sysfunc(rand(uniform));
This is because, in the macro environment, SAS interprets the text uniform as a string, while at the data stage, SAS interprets unquoted text as a variable name.
user667489
source share