Programming Statements |
Understanding Symbol Tables |
The scope of a variable is the set of locations in a program where a variable can be referenced. A variable defined outside of any module is said to exist at the program’s main scope. For a variable defined inside a module, the scope of the variable is the body of the module.
A symbol is the name of a SAS/IML matrix. For example, if x and y are matrices, then the names 'x' and 'y' are the symbols. Whenever a matrix is defined, its symbol is stored in a symbol table. There are two kinds of symbol tables. When a matrix is defined at the main scope, its name is stored in the global symbol table. In contrast, each module with arguments is given its own local symbol table that contains all symbols used inside the module.
There can be many local symbol tables, one for each module with arguments. (Modules without arguments are described in the next section.) You can have a symbol 'x' in the global table and the same symbol in a local table, but these correspond to separate matrices. By default, the value of the matrix at global scope is independent from the value of a local matrix of the same name that is defined inside a module. Similarly, you can have two modules that each use the matrix x, and these matrices are not related. You can force a module to use a variable at main scope by using a GLOBAL clause as described in Using the GLOBAL Clause.
Values of symbols in a local table are temporary; that is, they exist only while the module is executing. You can no longer access the value of a local variable after the module exits.
Copyright © SAS Institute, Inc. All Rights Reserved.