Introduction

You can execute SAS statements repeatedly by placing them in a DO loop. DO loops can execute any number of times in a single iteration of the DATA step. Using DO loops lets you write concise DATA steps that are easier to change and debug.

For example, the DO loop in this program eliminates the need for 12 separate programming statements to calculate annual earnings:

     data finance.earnings;
        set finance.master;
        Earned=0;
        do count=1 to 12;
           earned+(amount+earned)*(rate/12);
        end;
     run;

You can also use DO loops to

  • generate data
  • conditionally execute statements
  • read data.

This lesson shows you how to construct DO loops and how to include them in your programs.



1.5 hours



In this lesson, you learn to

  • construct a DO loop to perform repetitive calculations
  • control the execution of a DO loop
  • generate multiple observations in one iteration of the DATA step
  • construct nested DO loops.

complete the following lessons:

  • .