BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Jack2012
Obsidian | Level 7
%let p0=0.05;
%let p1=0.25;
%let alpha=0.1;
%let beta=0.1; 
%let usern=15;

 ****Stage 1;
  data stage1;
     do n1=5 to &usern-1;/*The totals ACCEPTABLE size is set sas "usern", n1 is the total size to be studied at stage 1*/
     do r1=0;
     term1_p0 = cdf('BINOMIAL', r1, &p0, n1);/*PET: probability of terminate after stage 1 when the drug is ineffective;This is also the Type I ERROR at stage 1*/
     term1_p1 = cdf('BINOMIAL', r1, &p1, n1);/*Probability of early ternation after stage 1 when, in fact, the drug is effective;*/
     if term1_p1=<&beta then output; /*remove solution sets that do not meet the beta requirement; This is the type II ERROR occurred at stage 1*/
     end;
     end;
  run;
  
  *****Stage 2; 
  data stage12; 
  	set stage1;
  	do n2=n1+1 to &usern-1;
  		do r2=r1+1 to n2 while (r1<r2<n2);
  			**term2_p0=0; *****initialize the summation terms for alpha & beta calculations;
  			**term2_p1=0;
  			do x1=r1+1 to min(r2, n1);/*x1: stand for the possible number of responses at stage 2 ONLY*/
  				**dum0=pdf('BINOMIAL', x1, &p0, n1)*cdf('BINOMIAL', r2-x1, &p0, n2-n1);
  				**dum1=pdf('BINOMIAL', x1, &p1, n1)*cdf('BINOMIAL', r2-x1, &p1, n2-n1);
  				**term2_p0= term2_p0+dum0;*recursive formulae used for summation terms;
  				**term2_p1= term2_p1+dum1;
				output;
  			end;
  			output;/*Remove the conditions "1-(term1_p0+term2_p0)=<&alpha and" */
  		end;
  	end;
  run;

Regard to the above code, how could the value of X1 be greater than r2 as shown in below shot?

do loop question.png

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star
Take a simple case:

do v1 = 1 to 5;
end;
Output;

The final value of v1 is 6, not 5. Each time through the loop, SAS gets to the END statement and adds 1 to v1. So the fifth time through v1 increases from 5 to 6. SAS now notices that the loop is done because v1 exceeds the upper range of the loop.

Similarly, in your loop the loop is over when x1 exceeds min(r2, n1) and the final OUTPUT statement outputs (below the loop) that result.

View solution in original post

2 REPLIES 2
Astounding
PROC Star
Take a simple case:

do v1 = 1 to 5;
end;
Output;

The final value of v1 is 6, not 5. Each time through the loop, SAS gets to the END statement and adds 1 to v1. So the fifth time through v1 increases from 5 to 6. SAS now notices that the loop is done because v1 exceeds the upper range of the loop.

Similarly, in your loop the loop is over when x1 exceeds min(r2, n1) and the final OUTPUT statement outputs (below the loop) that result.
Jack2012
Obsidian | Level 7

Thank yo so much for your helpl. Got now. 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 325 views
  • 0 likes
  • 2 in conversation