Constructing DO Loops

Overview

DO loops process a group of statements repeatedly rather than once. This can greatly reduce the number of statements required for a repetitive calculation. For example, these twelve sum statements compute a company's annual earnings from investments. Notice that all 12 statements are identical.
 data finance.earnings; set finance.master; Earned=0; earned+(amount+earned)*(rate/12); earned+(amount+earned)*(rate/12); earned+(amount+earned)*(rate/12); earned+(amount+earned)*(rate/12); earned+(amount+earned)*(rate/12); earned+(amount+earned)*(rate/12); earned+(amount+earned)*(rate/12); earned+(amount+earned)*(rate/12); earned+(amount+earned)*(rate/12); earned+(amount+earned)*(rate/12); earned+(amount+earned)*(rate/12); ...

Get SAS Certification Prep Guide: Base Programming for SAS 9, Third Edition 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.