全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
6043 3
2008-09-16
例如:有个循环,要求满足条件是就跳出循环执行循环后面的语句。

%do while(...);
%if condition then
跳出循环或者执行下次循环;
%end;
....
...


类似于C语言中的break和continue语句的功能,谁知道?

[此贴子已经被作者于2008-9-16 13:47:09编辑过]

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2008-9-16 14:10:00
Leave和continue

Leave表示从循环中退出,而continue表示跳过此轮循环,继续下一轮循环。例如

data leave_it;
   Interest = .0375;
   Total = 100;
    do Year = 1 to 100;
         Total = Total + Interest*Total;
         output;
         if Total ge 200 then leave;
     end;
    format Total dollar10.2;
run;

当总数大于或等于200时,则退出循环。

data continue_on;
  Interest = .0375;
  Total = 100;
  do Year = 1 to 100 until (Total ge 200);
      Total = Total + Interest*Total;
      if Total le 150 then continue;
      output;
   end;
format Total dollar10.2;
run;

只要Total小于或等于150,执行语句会跳到loop底部,而忽略output。

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2008-9-16 15:37:00

这个是在data步中的

我问的是在macro中的语句

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2008-9-17 02:03:00

%goto quit;

See this -

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

CONDITIONALLY PROCESS THE DATA SET OR END EXECUTION OF THE MACRO

The %INCLUDE statement retrieves SAS source code from an external file. The SOURCE2 option causes the

inserted SAS statements to appear in the SAS log. The PROCESSDATA.SAS program contains a DATA step and

two PROC steps to read and process the specified data set and create two reports. %QUIT is a macro label; in this

macro, the %QUIT is right before the %MEND. When the %GOTO statement branches macro processing to the

%QUIT label, the macro execution stops.

%include "c:\workshop\ws126\processdata.sas" / source2;

%quit:

%mend expense1;

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

Source: http://www2.sas.com/proceedings/sugi29/126-29.pdf

[此贴子已经被作者于2008-9-17 14:44:53编辑过]

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群