/***************************************************************************************************************** SAS file name: DoWhile_vs_DoUntil File location: _________________________________________________________________________________________________________________ Purpose: To demonstrate the differences between the do while and the do until loop in SAS Author: Peter Clemmensen Creation Date: 14/04/2019 This program supports the example page "Do While Loop vs Do Until Loop Explained in SAS" on SASnrd.com *****************************************************************************************************************/ /* Do Until loop executes at least once */ data _null_; a=1; do until (a ne 2); put "This is executed even though the condition is false"; end; run; data _null_; a=1; do while (a=2); put "This is not executed because the condition is false"; end; run; /* Do While Evaluates expression at the Top, Do Until Evaluates at the Bottom */ data _null_; a=1; do while(a < 3); /* Do While loop evaluates expression at the top */ put "Inside Loop " a=; a=sum(a, 1); end; put // "Outside Loop " a=; run; data _null_; a=1; do until(a > 3); put "Inside Loop " a=; a=sum(a, 1); end; /* Do Until loop evaluates expression at the bottom */ put // "Outside Loop " a=; run;