Conditionally Executing DO Loops

Overview

The iterative DO statement specifies a fixed number of iterations for the DO loop. However, there are times when you want to execute a DO loop until a condition is reached or while a condition exists, but you do not know how many iterations are needed.
Suppose you want to calculate the number of years required for an investment to reach $50,000. In the DATA step below, using an iterative DO statement is inappropriate because you are trying to determine the number of iterations required for Capital to reach $50,000.
data work.invest; 
  do year=1 to ? ; 
    Capital+2000; 
    capital+capital*.10; 
  end; 
run;
The DO WHILE and DO UNTIL statements enable you to execute DO loops based on whether a condition is true ...

Get SAS Certified Specialist Prep Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.