BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AThomalla
Obsidian | Level 7

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;
1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

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);

View solution in original post

1 REPLY 1
Rick_SAS
SAS Super FREQ

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);

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 711 views
  • 1 like
  • 2 in conversation