BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
runningneptune
Fluorite | Level 6

Community,

I want to perform a numerical integration for the following integrand

Capture.PNG

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;

 call quad(final,"grand",interval) eps=eps;
 return(final);

finish;

eps = 1E-11;

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

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

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

 

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

View solution in original post

5 REPLIES 5
ballardw
Super User

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

No output? Post any log in a code box.

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?

IanWakeling
Barite | Level 11

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

Rick_SAS
SAS Super FREQ

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

 

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

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

runningneptune
Fluorite | Level 6

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!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 5 replies
  • 704 views
  • 4 likes
  • 4 in conversation