Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 07-18-2019 12:17 PM
(1080 views)

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;

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

```
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.

3 REPLIES 3

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

you clearly have an unbalanced parentheses in your return statement in Func(x). Try fixing it first.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thanks Imvash for your hint. I corrected the place. But still, it does not function.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

```
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.

Are you ready for the spotlight? We're accepting content ideas for **SAS Innovate 2025** to be held May 6-9 in Orlando, FL. The call is **open **until September 25. Read more here about **why** you should contribute and **what is in it** for you!

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.