Statistical programming, matrix languages, and more

Using global variables in NLPTR

Posts: 21

Using global variables in NLPTR

I am trying to figure out how I can use a global variable while using NLPTR. I have added code snippet below. I am able to access global variable (x) from within funcB if I have no arguments to funcA. I understand the explanation around the global and the local variable tables. But is there a way around this limitation. I can't pass x as an argument to funcB in my code as nlptr will only let me pass more than 1 arguments. The other solution I have to use the funcA completely. But then my code won't be modular.

proc iml;

z = 10;

start funcA(z);

x = z/2;

start funcB(a,b) global(x);
b = a + x;
print 'In Function B' b;

a = 10;
call funcB(a,b);
print 'In Function A' b;


run funcA(z);

Posts: 3,232

Re: Using global variables in NLPTR

In the "Programming Statements" chapter of the SAS/IML doc, there's a section on "Nesting Modules" that contains the key to your problem:

I think from your question that you are expecting the local symbol table of the outer module to be the "global" symbol table of the inner module. This is not the case. There is one global symbol table (shared by all modules) and each module has a local symbol table.

One way to solve your problem is to use a GLOBAL(x) clause for both funcA and funcB.
Post a Question
Discussion Stats
  • 1 reply
  • 2 in conversation