SAS中文论坛

标题: SCL里面的leave语句 [打印本页]

作者: shiyiming    时间: 2006-6-30 00:02
标题: SCL里面的leave语句
最近看到leave语句,发现很好用,但是目前我只晓得它在do循环里面怎么用;然而它说到leave不但可以和do循环还可以和select组一起使用,所以我就不知道它怎么和select一起使用了,另外还看到这样一段话:
If you have nested DO loops and you want to skip out of more than one loop, you can specify the label of the loop that you want to leave. For example, the following LEAVE statement causes execution to skip to the last PUT statement:
myloop:
do i=1 to 10;
  do j=1 to 10;
    if j=5 then leave myloop;
    put i= j=;
  end;
end;
put 'this statement executes next';
return;
  

In SCL applications, the LEAVE statement can be used only within DO loops, not in SELECT statements (unless it is enclosed in a DO statement).

如果那位同仁晓得如何操作,还望多加指教,感激不尽!最好提供一个例子哈 ,嘿嘿!
作者: shiyiming    时间: 2006-7-6 15:32
标题: scl leave
The LEAVE statement is provided in SCL to control the execution of DO groups. When you need to force the statements in a DO group to stop executing, you can use the LEAVE statement to stop executing statements in a DO group and to start executing a statement that is outside of that DO group.

Note:   In DATA step code, the LEAVE statement stops processing only the current DO loop. In SCL code, the LEAVE statement stops processing the current DO loop or DO group, whichever is closest. For example, suppose your code contains a DO loop that contains DO groups:

do n=1 to 5;     /* DO loop */
    if n=3 then do; leave; end;        /* DO group */
  put n=;
end;
When this code is compiled and run as part of an SCL program, the output is:
n=1
n=2
n=3
n=4
n=5
When this code is submitted as part of a DATA step, the output is:
n=1
n=2
n=3
See DO for more information on DO groups and DO loops.  
For details about the LEAVE statement in the base SAS language, see SAS Language Reference: Dictionary.

--------------------------------------------------------------------------------

Examples



Example 1: LEAVE Statements Without Label Names
If a LEAVE statement does not contain the name of a program label, the program stops executing the statements in the DO group and starts executing the first statement after the DO group's END statement. For example, when the condition in the IF statement in the following program is true (that is, when the value of SUM > 10), the program jumps immediately to the statement following the END statement (in this case, the PUT statement).

INIT:
return;

MAIN:
do while(i<5);
   sum+i;
   i=i+2;
   if (sum>10) then
     do;
        leave;
     end;
   put sum=;
   end;
totalsum=sum;
return;
TERM:
return;


Example 2: LEAVE Statements With Label Names
In this example, when the condition SUM > 50 is true, the program leaves the LAB1 DO group and returns to the next statement following the DO group (in this case, the PUT statement).

INIT:
   sum=45;
return;
MAIN:
   link LAB1;
return;
LAB1:
   do i=1 to 10;
      if (sum>10) then do;
         k=0;
         do until (k>=20);
            sum+k;
            if (sum>50) then leave LAB1;
            k+2;
         end;
      end;
   end;
   put 'LEAVE LAB1, sum >50 ' sum=;
return;
TERM:
return;
作者: shiyiming    时间: 2006-7-6 15:34
标题: scl
不知道有用与否,我现在很忙,没时间仔细看你的问题,呵呵,现在做scl的项目,不过也是没有这方面的资料,如果哪位有共享一下啊
作者: shiyiming    时间: 2006-7-6 16:19
标题: next
The LEAVE statement, when used inside a SELECT group, causes execution to continue processing with
the next statement following the SELECT group. It’s like a GOTO statement, but you don’t have to name
the place you’re going to.




欢迎光临 SAS中文论坛 (http://mysas.net/forum/) Powered by Discuz! X3.2