Programming Statements


Using the GLOBAL Clause

For modules with arguments, the variables used inside the module are local and have no connection with any variables that exist outside the module in the global table. However, it is possible to specify that certain variables not be placed in the local symbol table but rather be accessed from the global table. The GLOBAL clause specifies variables that you want to share between local and global symbol tables. The following is an example of a module that uses a GLOBAL clause to define the symbol c as global. This defines a one-to-one correspondence between the value of c in the global symbol table and the value of c in the local symbol table.

proc iml;
a = 10;
b = 20;
c = 30;
start Mod4(x,y) global (c);
   x = 100;
   c = 40;
   b = 500;
finish Mod4;

run Mod4(a,b);
print a b c;

The output is shown in FigureĀ 6.9.

Figure 6.9: Output from a Module with a GLOBAL Clause

a b c
100 20 40



After the module is called, the following facts are true:

  • a is changed to 100.

  • b is still 20 and not 500, since b exists independently in the global and local symbol tables.

  • c is changed to 40 because it was declared to be a global variable. The matrix c inside the module is the same matrix as the one outside the module.

Because every module with arguments has its own local table, it is possible to have many local tables. You can use the GLOBAL clause with many (or all) modules to share a single global variable among many local symbol tables.