Chapter 9: Arithmetic

9.1 Basic Rules

9.2 Truth in Numbers, Expressions, and Comparisons

9.2.1 Programming Challenge #7

9.2.2 Solution

The basics may bore you, but the details will delight you.

9.1 Basic Rules

The %LET statement automatically ignores arithmetic:

%let total =  3 * 5   ;

Here, &TOTAL is five characters long, and the third character is an asterisk. As usual, leading and trailing blanks are ignored. For the %LET statement to perform arithmetic, it must apply a function:

%let total = %eval(3 * 5);           15

%let total = %sysevalf(3 * 5);     15

The %EVAL function performs integer arithmetic, dropping any remainders:

%let total = %eval(10 / 4);    2

%let total = %eval(2.5 * 4);   error, decimal points not allowed

%let total = %eval(10./4.);    ...

Get SAS Macro Language Magic now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.