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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 1 reply
  • 1576 views
  • 0 likes
  • 2 in conversation