Hello everyone, we have a problem when we call the FROOT function within a module. If the module is parameterized, we get an error message. We do not understand why. The following is the example code. Once without parameter transfer in the module (parameters a,b,c are initialized within the module). And once with passing the parameters in the module call.
What is the problem? Obviously a module in which FROOT is called cannot be parameterized.
How can the problem be solved?
Thanks in advance!
/*Nonlinear solver without error*/
proc iml;
start func(x) global(a,b,c);
measure = (a/x+b/x##2 - c);
return(measure);
finish func;
store module=func;
start getSolution_m;
a = 215;
b = 231.5;
c = 400;
interval = {0.01 2};
roots = froot( "Func", interval);
print roots;
finish;
store module=getSolution_m;
quit;
proc iml;
load;
call getSolution_m;
quit;
/*Nonlinear solver with error*/
proc iml;
start func(x) global(a,b,c);
measure = (a/x+b/x##2 - c);
return(measure);
finish func;
store module=func;
start getSolution_m(a,b,c);
interval = {0.01 2};
roots = froot( "Func", interval);
print roots;
finish;
store module=getSolution_m;
quit;
proc iml;
load;
call getSolution_m(215,231.5,400);
quit;
In the second program (which doesn't work), the FUNC module is trying to refer to global symbols a,b, and c, but there are no symbols by that name in the global symbol table. To review how global variables work in SAS/IML, see the article "Understanding local and global variables in the SAS/IML language."
To solve your problem, you can either define (a,b,c) in the main scope of the program, or you can have the GetSolution_m module update the global symbol table by copying its parameters into the global symbols. It sounds like you want the second option. For clarity, the following program uses g_a, g_b, and g_c as the name of the global variables:
proc iml;
start func(x) global(g_a,g_b,g_c);
measure = (g_a/x+g_b/x##2 - g_c);
return(measure);
finish func;
store module=func;
start getSolution_m(a,b,c) global(g_a,g_b,g_c);
g_a = a; g_b = b; g_c = c; /* copy parameters into the global symbols */
interval = {0.01 2};
roots = froot( "Func", interval);
print roots;
finish;
store module=getSolution_m;
quit;
proc iml;
load;
call getSolution_m(215,231.5,400);
In the second program (which doesn't work), the FUNC module is trying to refer to global symbols a,b, and c, but there are no symbols by that name in the global symbol table. To review how global variables work in SAS/IML, see the article "Understanding local and global variables in the SAS/IML language."
To solve your problem, you can either define (a,b,c) in the main scope of the program, or you can have the GetSolution_m module update the global symbol table by copying its parameters into the global symbols. It sounds like you want the second option. For clarity, the following program uses g_a, g_b, and g_c as the name of the global variables:
proc iml;
start func(x) global(g_a,g_b,g_c);
measure = (g_a/x+g_b/x##2 - g_c);
return(measure);
finish func;
store module=func;
start getSolution_m(a,b,c) global(g_a,g_b,g_c);
g_a = a; g_b = b; g_c = c; /* copy parameters into the global symbols */
interval = {0.01 2};
roots = froot( "Func", interval);
print roots;
finish;
store module=getSolution_m;
quit;
proc iml;
load;
call getSolution_m(215,231.5,400);
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.