SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Search||next

Generating Data with DO Loops
Lesson Overview


Introduction

You can execute SAS statements repeatedly by placing them in a DO loop. Unlike simple DO statements, which execute as a group when an IF condition is met, DO loops 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 alter 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 include them in your programs.

This lesson contains 31 pages and takes approximately 45-60 minutes to complete.


Objectives

After completing this lesson, you will be able 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 have completed the following lessons:

Getting Started with SAS Programming

Creating and Modifying Variables

DATA Step Processing


||next


Copyright © 2002 SAS Institute Inc., Cary, NC, USA. All rights reserved.

Terms of Use & Legal Information | Privacy Statement