O'Reilly logo

SAS Macro Language Magic by Robert Virgile

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.);    ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required