Contributor
Posts: 20

# help in CALL NLPQN inside PROC IML

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
SAS Super FREQ
Posts: 4,175

## Re: help in CALL NLPQN inside PROC IML

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?
Discussion stats