I run the code to optimizing loglikelihood like the following in SAS9.2/IML:
start ML (x) ;
dp=1;x1=2;,x2=3;
star ls(a) global(dp, x1,x2);
z=SSQ(dp-a[1]#x1-a[2]#x2);
return(z);
finish LS;
x={3 3};
call nlpnrr(rc,rx,"LS",x);
....
finish ML;
x={0,1};
call nlpnms(rc,xr,"ML",x);
there is a error message in log window as following:
ERROR: (execution) Matrix has not been set to a value.
operation : # at line 1803 column 30
operands : _TEM1001, x1
_TEM1001 1 row 1 col (numeric)
3
x1 0 row 0 col (type ?, size 0)
statement : ASSIGN at line 1803 column 17
traceback : module LS at line 1803 column 17
module ML at line 1635 column 1
ERROR: (execution) Matrix has not been set to a value.
operation : NLPNRR at line 1686 column 16
operands : *LIT1074, x, , con
*LIT1074 1 row 1 col (character, size 2)
ls
x 1 row 2 cols (numeric)
3 3
con 2 rows 2 cols (numeric)
. .
. 50
statement : CALL at line 1686 column 16
traceback : module ML at line 1686 column 16
When i use a Global clause in Start ML(x) as
Start ML(x) Global(dp, x1,x2);
there is not error message.
My question is :
Since x1 and x2 are defined with global clause in moldule ML before model LS, they are global variables for module LS, Why error message say that? What's the function of the Global clause in "Start ML(x) Global
(dp, x1,x2);"
Thanks alot!
There is no such thing as a nested module. All modules are known globally. If you want to share variable names between two modules, you can use the GLOBAL statement on each START statement. In your case, you would use
global(dp, x1,x2);
for both the ML and LS modules.
For details, see the article Local functions (not!) in the SAS/IML language - The DO Loop
By the way, your LS function doesn't have a unique minimum. It has a trough, which will probably result in the optimization step not converging. Notice that the gradient of LS is
start grdLS(a) global(dp, x1,x2);
return( -x1 || -x2 );
finish;
The gradient is a constant vector, so it never vanishes unless x1 and x2 are identically zero.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.