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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

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