Fluorite | Level 6

## a numerical integration problem

Community,

I want to perform a numerical integration for the following integrand

C1, delta11, d1, rho are all scalar, which will be specified explicitly. \phi(u) is the PDF of a standard normal distribution, \Phi() is the CDF of a standard normal distribution. I proposed the following SAS codes, but I failed, so there must be something very wrong. Can you kindly help? Thanks in advance!

*************************************************************************************************
proc iml;
start stdn(u);
pi = constant("Pi");
z=(1/sqrt(2#pi))#exp((-1/2)#(u#u));
return(z);
finish;

start phi(u) global(d1,rho);
cdf=probnorm((-d1+rho#u)/sqrt(1-rho#rho));
return(cdf);
finish;

start grand(u);
v=phi#stdn;
return(v);
finish;

start integral(cc1,ddelta1,dd1,rrho) global(c1,delta1,d1,rho,eps);
c1=cc1;
delta1=ddelta1;
d1=dd1;
rho=rrho;
ll=c1-delta1;
interval=ll||.P;

return(final);

finish;

eps = 1E-11;

p=integral(1.678, 1, 1.645, 0.6);
print p;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
SAS Super FREQ

## Re: a numerical integration problem

As Ian points out, the mistake in the 'grand' function. Try

start grand(u);
v=phi(u)#stdn(u);
return(v);
finish;
5 REPLIES 5
Super User

## Re: a numerical integration problem

"Failed" is awful vague.

Are there errors in the log?: Post the code and log in a code box opened with the <> to maintain formatting of error messages.

Unexpected output? Provide input data, if any, in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the </> icon or attached as text to show exactly what you have and that we can test code against.

Or how do you know it failed?

Barite | Level 11

## Re: a numerical integration problem

I have not tried to check the integration itself,  but just looking at your code I can see a few issues that need attention.  In the module called 'grand'  you are attempting to call the modules 'phi' and 'stdn', however both require an argument 'u'.  Secondly, you should terminate the IML code with 'quit' instead of 'run'.

SAS Super FREQ

## Re: a numerical integration problem

As Ian points out, the mistake in the 'grand' function. Try

start grand(u);
v=phi(u)#stdn(u);
return(v);
finish;
Fluorite | Level 6

## Re: a numerical integration problem

Thanks a lot Rick, it works. I will reply to Ian to thank him as well.

Fluorite | Level 6

## Re: a numerical integration problem

Thanks a lot Ian, all valid comments, I cleared it up and now it works just fine. Thank you and Rick for your collaborative guidance!

From The DO Loop