BookmarkSubscribeRSS Feed
aya123
Calcite | Level 5
There is an error during running this code, can you help me to find the mistake?


proc iml;
start fun(K);
f = sumf;
sumf=0;
do i = 1 to 3;
sumf = sumf + (estvar*lambda)+ (g* k)**2 /(lambda+ k)**2;
end;
return (f);
finish fun;
start con(k);
c=j(4,1,0);
sumc1=0;
do i = 1 to 3;
sumc1 = sumc1 + (col1**2 *lambda/(lambda+k)**2);
end;
c[1]= 10-sumc1;
sumc2=0;
do i= 1 to 3;
sumc2 = sumc2 + (col2**2 *lambda/(lambda+k)**2);
end;
c[2]= 10-sumc2;
sumc3=0;
do i= 1 to 3;
sumc3 = sumc3 + (col3**2 *lambda/(lambda+k)**2);
end;
c[3]= 10-sumc3;
c[4]=(max(lambda)/min(lambda))-(max(lambda)+k)/(min(lambda)+k);
return (c);
finish con;
k=j(1,1,0);
optn=j(0,11,.); optn[1]=0; optn[2]=4; optn[4]=1; optn[6]=2;
optn[11]=0; optn[10]=4;
call nlpqn (rc, kres, "fun", k, optn) nlc="con";
print k;

where g,l,estvar,col1,col2,col3 are vectors
and k is a decision variable
1 REPLY 1
Rick_SAS
SAS Super FREQ
You didn't give the error message, so I don't know which of the errors you might be referring to. I see a few:
(1) SAS/IML indexes vectors from 1, so the expression optn=j(0,11,.) is incorrect.
(2) IML uses local variables in modules, so the variables estvar,col1,col2,col3, etc, are undefined within the modules. Maybe you intended to use a GLOBAL clause?

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 975 views
  • 0 likes
  • 2 in conversation