Sas 简明教程

SAS - Loops

在某些情况下,需要执行一个代码块多次。通常,语句顺序执行——函数中的第一个语句首先执行,接着执行第二个语句,依此类推。但是,当您希望同组语句重复执行时,我们需要循环的帮助。

You may encounter situations, when a block of code needs to be executed several number of times. In general, statements are executed sequentially − The first statement in a function is executed first, followed by the second, and so on. But when you want the same set of statements to be executed again and again, we need the help of Loops.

在 SAS 中,使用 DO 语句进行循环。它也被称为 DO Loop 。下面给出了 SAS 中 DO 循环语句的常用形式。

In SAS looping is done by using DO statement. It is also called DO Loop. Given below is the general form of a DO loop statements in SAS.

Flow Diagram

SAS do while loop

以下是 SAS 中的 DO 循环类型。

Following are the types of DO loops in SAS.

Sr.No.

Loop Type & Description

1

DO Index.The loop continues from the start value till the stop value of the index variable.

2

DO WHILE.The loop continues till the while condition becomes false.

3

DO UNTIL.The loop continues till the UNTIL condition becomes True.