BookmarkSubscribeRSS Feed
model_coder
Calcite | Level 5
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;
finish;

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

finish;

run funcA(z);

quit;
1 REPLY 1
Rick_SAS
SAS Super FREQ
In the "Programming Statements" chapter of the SAS/IML doc, there's a section on "Nesting Modules" that contains the key to your problem: http://support.sas.com/documentation/cdl/en/imlug/59656/HTML/default/programstatements_sect8.htm

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.

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register now

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 1 reply
  • 1323 views
  • 0 likes
  • 2 in conversation