Hi,
I am new to proc iml. I read that froot function could replicate excel sovler. I try to solve an equation towards the variable x, which is supposed to a number between -1 and 1, but I got the error: invalid Operation. I am guessing I put in the wrong bound. Could someone please help me with this Problem?
Many thanks!
Best
data have;
input D0 D1 D2 D3;
ZERO = 0;
ID = _N_;
datalines;
0.1 0.45 100 80
0.05 0.5 200 150
0.3 0.45 300 180
0.5 0.6 400 200
0.15 0.6 500 200
;
run;
proc iml;
start Func (x) global (D0, D1, D2, D3);
return ((CDF('NORMAL',(Quantile('NORMAL',D1) + sqrt(x)*Quantile('NORMAL', .999))/sqrt(1-x), 0, 1)-D0)*D1*D2 - D3);
finish;
use have;
read all var {D0 D1 D2 D3} into D;
close;
x=j(nrow(D),1);
do i=1 to nrow(D);
D0= D[i,1]; D1= D[i, 2]; D2 = D[i, 3]; D4 =D[i,4];
x[i]=froot("Func", {-1,1});
end;
print x;
data have;
input D0 D1 D2 D3;
datalines;
0.1 0.45 100 80
0.05 0.5 200 150
0.3 0.45 300 180
0.5 0.6 400 200
0.15 0.6 500 200
;;
run;
proc iml;
start Func (x) global (D0, D1, D2, D3);
return ((CDF('NORMAL',(Quantile('NORMAL',D1) + sqrt(x)*Quantile('NORMAL', .999))/sqrt(1-x), 0, 1)-D0)*D1*D2 - D3);
finish;
use have;
read all var {D0 D1 D2 D3} into D;
close;
x=j(nrow(D),1);
do i=1 to nrow(D);
D0 = D[i, 1];
D1 = D[i, 2];
D2 = D[i, 3];
D3 = D[i, 4];
x[i] = froot("Func", {0 0.999});
end;
print x;
quit;
This script does not return any error messages. You had introduced D4 in your loop; I changed it to D3. Your input x boundaries should be well-defined (greater than zero and less than 1, as you had sqrt(x) in your function and division by sqrt(1-x)). Apparently, you do not have any feasible solution in the first 4 iterations.
you clearly have an unbalanced parentheses in your return statement in Func(x). Try fixing it first.
Thanks Imvash for your hint. I corrected the place. But still, it does not function.
data have;
input D0 D1 D2 D3;
datalines;
0.1 0.45 100 80
0.05 0.5 200 150
0.3 0.45 300 180
0.5 0.6 400 200
0.15 0.6 500 200
;;
run;
proc iml;
start Func (x) global (D0, D1, D2, D3);
return ((CDF('NORMAL',(Quantile('NORMAL',D1) + sqrt(x)*Quantile('NORMAL', .999))/sqrt(1-x), 0, 1)-D0)*D1*D2 - D3);
finish;
use have;
read all var {D0 D1 D2 D3} into D;
close;
x=j(nrow(D),1);
do i=1 to nrow(D);
D0 = D[i, 1];
D1 = D[i, 2];
D2 = D[i, 3];
D3 = D[i, 4];
x[i] = froot("Func", {0 0.999});
end;
print x;
quit;
This script does not return any error messages. You had introduced D4 in your loop; I changed it to D3. Your input x boundaries should be well-defined (greater than zero and less than 1, as you had sqrt(x) in your function and division by sqrt(1-x)). Apparently, you do not have any feasible solution in the first 4 iterations.
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!
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.