backnextLearning Path
   


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.



Time to Complete

This lesson contains pages and takes approximately 1.5 hours to complete.



Objectives

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.

Prerequisites

Before taking this lesson, you should complete the following lessons:

  • .

  Copyright © 2003 SAS Institute Inc., Cary, NC, USA. All rights reserved.
Terms of Use & Legal Information | Privacy Statement
backnext