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

Dears,

 

I am trying to apply the minimization algorithm mentioned in the attached pdf with SAS 9.2. 

 

I am using the following code with the data attached (values already centered).

 

proc iml;
use in_data;
read all into in_data;
in_data=in_data;

start F(x) global(in_data);
x = {0, 0, 0};
f = sum(exp(in_data*x));
return(f);
finish F;

start G(x) global(in_data);
x = {0, 0, 0};
g = (exp(in_data*x)`)*in_data;
return(g);
finish G;

x = {0, 0, 0};
optn = {0 2};
call nlpnra(rc, xres, "F", x, optn) grd="G";

print xres;
quit;

 

xres gives me the following result: 0.0301847 -0.008427 0.0540752

 

When I use R, I get the following results: 0.4941690 -0.2042731 1.5939447. I would like to know how could I fix the code so that the results are more similar to those provided by R.
 

Any help would be highly appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
IanWakeling
Barite | Level 11

I think the following will fix the problem.  Always use a row vector for x0 and don't try to modify x within the functions F and G.

 

proc iml;
use test;
read all into in_data;

start F(x) global(in_data);
f = sum(exp(in_data*x`));
return(f);
finish F;

start G(x) global(in_data);
g = (exp(in_data*x`)`)*in_data;
return(g);
finish G;

x0 = {0 0 0};
optn = {0 2};
call nlpnra(rc, xres, "F", x0, optn) grd="G";

print xres;
quit;

View solution in original post

2 REPLIES 2
IanWakeling
Barite | Level 11

I think the following will fix the problem.  Always use a row vector for x0 and don't try to modify x within the functions F and G.

 

proc iml;
use test;
read all into in_data;

start F(x) global(in_data);
f = sum(exp(in_data*x`));
return(f);
finish F;

start G(x) global(in_data);
g = (exp(in_data*x`)`)*in_data;
return(g);
finish G;

x0 = {0 0 0};
optn = {0 2};
call nlpnra(rc, xres, "F", x0, optn) grd="G";

print xres;
quit;
zocoj
Calcite | Level 5
Thanks a lot! it works :).

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 2 replies
  • 1150 views
  • 2 likes
  • 2 in conversation