SAS中文论坛

 找回密码
 立即注册

扫一扫,访问微社区

查看: 782|回复: 3
打印 上一主题 下一主题

SCL里面的leave语句

[复制链接]

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
楼主
 楼主| 发表于 2006-6-30 00:02:47 | 只看该作者

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).

如果那位同仁晓得如何操作,还望多加指教,感激不尽!最好提供一个例子哈 ,嘿嘿!
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
沙发
 楼主| 发表于 2006-7-6 15:32:51 | 只看该作者

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;
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
板凳
 楼主| 发表于 2006-7-6 15:34:57 | 只看该作者

scl

不知道有用与否,我现在很忙,没时间仔细看你的问题,呵呵,现在做scl的项目,不过也是没有这方面的资料,如果哪位有共享一下啊
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
地板
 楼主| 发表于 2006-7-6 16:19:11 | 只看该作者

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.
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SAS中文论坛  

GMT+8, 2025-6-10 05:29 , Processed in 0.081906 second(s), 22 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表