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

I m having issues with this, I have to compute numerical integral using if else statement

Data sim;

Input A B C Beta P;

cards;

1 2  3  0.5  0

2 3  4  0.5  1

3 4.5 3  0.5 1

3 5 6  0.5   0

;

Run;

proc iml;

use sim;

read all var _NUM_ into DM;

close;

A = DM[,1]; B = DM[,2]; C = DM[,3];  Beta = DM[,4];  P = DM[,5];

n = nrow(DM);

start Func(x) global( Beta_i, C_i , P_i);

if P_i=0 then do;

   return(  exp(-x)*exp(2-x +Beta_i*C_i)#(cdf("Normal", x-2+Beta_i*C_i + A_i)-cdf("Normal", x-1+C_i + A_i)) );

end;

else do;

return(  exp(-x)*exp(4-x +Beta_i*C_i)#(cdf("Normal", x-4 +Beta_i*C_i + A_i)-cdf("Normal", x-1+C_i + A_i)) );

end;

finish;

answer = j(nrow(DM),1);

do i = 1 to nrow(DM);

   Beta_i = Beta; C_i = C;  P_i=P; /* set global variables */

   call quad(result, "Func", A || B,);

   answer = result;

end;

create kaplan1n var{A  B C Beta P Answer };

append;

quit;

1 ACCEPTED SOLUTION

Accepted Solutions
2 REPLIES 2
Rick_SAS
SAS Super FREQ

A_i is not defined in the module.

desireatem
Pyrite | Level 9

Thanks Rick:

Data sim;

Input A B C Beta P;

cards;

1 2  3  0.5  0

2 3  4  0.5  1

3 4.5 3  0.5 1

3 5 6  0.5   0

;

Run;

proc iml;

use sim;

read all var _NUM_ into DM;

close;

A = DM[,1]; B = DM[,2]; C = DM[,3];  Beta = DM[,4];  P = DM[,5];

n = nrow(DM);

start Func(x) global( Beta_i, C_i , A_i, P_i);

if P_i=0 then do;

   return(  exp(-x)*exp(2-x +Beta_i*C_i)#(cdf("Normal", x-2+Beta_i*C_i + A_i)-cdf("Normal", x-1+C_i + A_i)) );

end;

else do;

return(  exp(-x)*exp(4-x +Beta_i*C_i)#(cdf("Normal", x-4 +Beta_i*C_i + A_i)-cdf("Normal", x-1+C_i + A_i)) );

end;

finish;

answer = j(nrow(DM),1);

do i = 1 to nrow(DM);

   Beta_i = Beta; C_i = C; A_i=A; P_i=P; /* set global variables */

   call quad(result, "Func", A || B,);

   answer = result;

end;

create kaplan1n var{A  B C Beta P Answer };

append;

quit;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 2 replies
  • 1921 views
  • 0 likes
  • 2 in conversation