Published on :
Macro CREATION_INTERNE

Macro-Variable Manipulation and Arithmetic Operations

This code is also available in: Deutsch Español Français
This script illustrates the fundamental concepts of the SAS© macro language: text assignment, the distinction between literal text and calculation, the use of %EVAL for integers and %SYSEVALF for floating-point numbers, as well as handling null variables.
Data Analysis

Type : CREATION_INTERNE


The script does not manipulate any SAS data tables (dataset). It acts only on the in-memory macro symbol table.

1 Code Block
MACRO STATEMENT
Explanation :
Creation of a macro-variable containing a character string and display of its resolved value in the log.
Copied!
1%LET myName = FirstName LastName;
2%PUT Hello World! My name is &myName;
3 
2 Code Block
MACRO STATEMENT
Explanation :
Definition of variables. Without an explicit evaluation function, '77 + 92' is treated as a literal text string and not as a mathematical operation.
Copied!
1/* a few more examples of variables */
2%Let age = 70;
3%Let twograde = 77 + 92;
4%Put &twograde
3 Code Block
MACRO STATEMENT
Explanation :
Using the %EVAL function to force the evaluation of an integer arithmetic expression.
Copied!
1%Let totgrade = %eval(77+92)
2%Put &totgrade
4 Code Block
MACRO STATEMENT
Explanation :
Using the %SYSEVALF function to evaluate arithmetic expressions containing decimal (floating-point) numbers.
Copied!
1%Let totprice = %sysevalf(77.5+92.1)
2%Put &totprice
5 Code Block
MACRO STATEMENT
Explanation :
Initialization of a macro-variable with a null value (empty string).
Copied!
1%Let state=;
2%Put &state;
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.