/* Example of using DO WHILE and DO UNTIL statements in SAS */ /* Program to determine the sample size needed for a sample mean of 0.1 to be judged */ /* significantly greater than zero at the 0.05 significance level by a t-test (when s=2). */ DATA results; sampmean = 0.1; sampsd = 2; sampsize = 10; tstat = sampmean / (sampsd / sqrt(sampsize) ); tcritval = tinv(0.95, sampsize-1); DO WHILE (tstat LE tcritval); tstat = sampmean / (sampsd / sqrt(sampsize) ); tcritval = tinv(0.95, sampsize-1); OUTPUT; sampsize = sampsize + 10; * sampsize + + 10; END; run; PROC PRINT DATA = results; RUN; /* Almost the same thing, but using DO UNTIL construction: */ DATA results; sampmean = 0.1; sampsd = 2; sampsize = 10; tstat = sampmean / (sampsd / sqrt(sampsize) ); tcritval = tinv(0.95, sampsize-1); DO UNTIL (tstat GT tcritval); tstat = sampmean / (sampsd / sqrt(sampsize) ); tcritval = tinv(0.95, sampsize-1); OUTPUT; sampsize = sampsize + 10; END; run; PROC PRINT DATA = results; RUN; /* Change sampsd to .002 in both cases and see the difference */ /* between DO WHILE and DO UNTIL in that situation. */