If a global macro variable It corresponds to a variable of the same name that exists at main scope. The %LOCAL that variable will be used only at the particular block only but in case of the %GLOBAL that variable will be used till the end of the SAS session. in the SAS/IML langauge - The DO Loop, Pingback: Handling run-time errors in user-defined modules - The DO Loop, Pingback: Ten tips before you run an optimization - The DO Loop, Pingback: Everything you wanted to know about writing SAS/IML modules - The DO Loop. A macro variable created with a %GLOBAL statement has a null value until you assign it some other value. Because x is an argument, changing x inside the function also changes t. See my previous article for more details about passing by reference. For example, the following SAS/IML program defines a variable y inside a function. The following example illustrates this: In this example, the y vector is changed from within the F3 function because y is declared to be a global variable. The %LET statement is one way to define a global macro variable. But when I run this code , the SAS log shows GLOBAL TESTVAR value1 %let testVar = value2; %macro test; %let testVar = value1; %mend; %test %put _all_; So, I can't understand why the value of the global variable testVar changed to value1. cannot use a SAS variable list or a macro expression that generates a SAS is the name of one or more macro variables creating macro variables in SAS, and also address their scope (local vs. global) and their values. already exists and you specify that variable in a %GLOBAL statement, the existing The local variable is created when the function executes and vanishes when the function exits. CALL SYMPUT CALL SYMPUT is a SAS language routine that assigns a value in a DATA step to a macro variable during execution time. The local variable named y is not related to the variable y in the main scope. When you submit the following program, the macro VARS I'm having trouble getting If/Then statements to work correctly with my macro variables inside a datastep. y=3*x Local Macro variable. What is the difference between %LOCAL and %GLOBAL? When the macro stops executing, all local macro variables for that macro cease to exist. generates the VAR statement and the values for the macro variables used in The behavior of the F2 function is summarized in the following diagram. Macro variables are not subject to the same length limits as SAS data set variables. There is a global symbol table, which contains global macro variables, and a local symbol table, which contains local macro variables. They are typically used to supply different variables to the same SAS statements sl that they can process different observations of a data set. Sometimes SAS/IML users ask if there is a third alternative. Automatic variables are global except SYSPBUFF, which is local. I always thought that %let creates a local variable if used inside of %macro . . the title statement. in the SAS/IML langauge - The DO Loop, Handling run-time errors in user-defined modules - The DO Loop, Ten tips before you run an optimization - The DO Loop, Everything you wanted to know about writing SAS/IML modules - The DO Loop. The local variable is created when the function executes and vanishes when the function exits. A macro variable created with a %GLOBAL statement has In SAS code: & name. During the debugging process, you may find it helpful on occasion to print these tables to examine the scope and values of a group of macro variables.