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 09-26-2014 04:50 PM
(924 views)

Hello, The if else statement run well with the same limit of integration A , B or interval (A,B). However I want to modify the code such that the first do statement should have limit of integration (A,B) as it is, but the else statement limit should change from (A,B) to (F,B).

That is the if statement limit of integration is** (A,B)** while else is **(F,B)**??? The different is the the lower limit of integration should change for the else statement from A to F.

I added comment and bold the sections of the code that need modification. Please ANY HELP?????????????

Please any suggestion ?

Data sim;

Input A B C Beta P F;

cards;

1 2 3 0.5 0 1

2 3 4 0.5 1 1

3 4.5 3 0.5 1 2

3 5 6 0.5 0 2

;

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]; F = DM[,6];

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)) ); /* The limits of integration is: call quad(result, "Func", A || B,); leave it as it is*/ **

**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)) ); /* The limits of integration is:call quad(result, "Func", A || B,); but I want to change it to call quad(result, "Func", F || B,) */ **

**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;

1 ACCEPTED SOLUTION

Accepted Solutions

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

Seem reasonable. It is fine to have a complicated integrand, but I personally think it is more readable and maintainable to have two integrands. You could define Func1 to be the integrand for P_i=0 and Func2 for the other case. Then you can get rid of P_i as a GLOBAL variable and write

** if P_i=0 then do;**

** call quad(result, "Func1", A || B);**

** end;**

** else do;**

** call quad(result, "Func2", F || B);**

** end;**

4 REPLIES 4

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

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

Hello Rick,

Is this correct? I changed the limit as shown below (BOLD).

Data sim;

Input A B C Beta P F;

cards;

1 2 3 0.5 0 1

2 3 4 0.5 1 1

3 4.5 3 0.5 1 2

3 5 6 0.5 0 2

;

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]; F = DM[,6];

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)) ); /* The limits of integration is:call quad(result, "Func", A* || B ,); leave it as it is*/*

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)) ); /* The limits of integration is:call quad(result, "Func", A* || B ,); but I want to change it to call quad(result, "Func", F || B,) */*

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 */**

** if P_i=0 then do;**

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

** end;**

** else do;**

** call quad(result, "Func", F || B,);**

** end;**

** answer = result;**

end;

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

append;

quit;

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

Seem reasonable. It is fine to have a complicated integrand, but I personally think it is more readable and maintainable to have two integrands. You could define Func1 to be the integrand for P_i=0 and Func2 for the other case. Then you can get rid of P_i as a GLOBAL variable and write

** if P_i=0 then do;**

** call quad(result, "Func1", A || B);**

** end;**

** else do;**

** call quad(result, "Func2", F || B);**

** end;**

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

Thanks a lot.

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

**If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. **

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.