楼主: Tigflanker
3592 2

求助一个data步leave问题 [推广有奖]

  • 8关注
  • 18粉丝

副教授

49%

还不是VIP/贵宾

-

威望
0
论坛币
2321 个
通用积分
9.9128
学术水平
179 点
热心指数
194 点
信用等级
167 点
经验
27443 点
帖子
622
精华
0
在线时间
851 小时
注册时间
2011-3-27
最后登录
2023-5-14

楼主
Tigflanker 发表于 2013-3-14 22:57:26 |AI写论文
100论坛币
求老师们一个data步的leave问题:

代码:%macro search(w0by,delby,sigby,sig1,sig2,need);

data _null_;
  do w0 =0 to 80 by &w0by;
    do delta10 =15 to 30 by &delby;
re:   do sigma10 =&sig1 to &sig2 by &sigby;
*循环体;
        /*output;*/
                    if nc<&need then do;
                              proc sql;
                             insert into result
                            value(wo,delta10,sigma10,nc);
                            select wo,delta10,sigma10,nc from result;
                            quit;
                        end;
                        if nc<&need then leave;
                        
                    if nc<0 then do;
                        call symputx("sig1",symget("sigma10")-&sigby);
                        call symputx("sig2",symget("sigma10"));
            call symputx("sigby",symget("sigby")/10);
                        end;
                        if nc<0 then go to re;
      end;
    end;
  end;
run;

%mend;

%search(10,5,10,50,150,0.001);

log提示如下错误:

NOTE: Table WORK.RESULT created, with 0 rows and 4 columns.
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.21 seconds
      cpu time            0.09 seconds



NOTE: Line generated by the invoked macro "SEARCH".
3      data _null_;   do w0 =0 to 80 by &w0by;     do delta10 =15 to 30 by &delby;       do sigma10 =&sig1 to &sig2 by
3  ! &sigby; *body;                      if nc<&need then do;                 proc sql;                 insert into
                                                                             -
                                                                             117
3  ! result                 value(
ERROR 117-185: There were 4 unclosed DO blocks.

NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
      real time           0.09 seconds
      cpu time            0.01 seconds


1: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL may allow recovery of the LINE and COLUMN where the error has
      occurred.
WARNING 1-322: Assuming the symbol VALUES was misspelled as value.
NOTE: Line generated by the invoked macro "SEARCH".
4    wo,delta10,sigma10,nc);
     --
     22
     76
ERROR 22-322: Syntax error, expecting one of the following: a quoted string, a numeric constant, a datetime constant,
              a missing value, +, -, MISSING, NULL, USER.


ERROR 76-322: Syntax error, statement will be ignored.


ERROR: The following columns were not found in the contributing tables: wo.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.12 seconds
      cpu time            0.03 seconds



我的想法:

我想做的是在这三层循环中的最里面那层做一个迭代,当最里面那层循环满足某种条件后:1,修改约束条件;2,跳出最里面的循环体重新循环。

我现在先不管迭代正确与否的事,我只想知道,为什么leave失效了,为什么会提示我丢了四个end;我想用leave实现的功能是:伴随leave得到的结果,跳出最内层循环,继续第二层循环。
求助请各位朋友,谢谢。



最佳答案

matchlessboy 查看完整内容

这里不能直接用proc sql, 如果要用的话,可以把整个sql的部分放在一个call execute()里面。 你说的丢失end的问题就是因为,sas读到proc sql的时候它以为整个data step结束了。
关键词:Leave data步 Data AVE EAV return
Bye SAS.
若有缘,能重聚。

沙发
matchlessboy 发表于 2013-3-14 22:57:27
这里不能直接用proc sql, 如果要用的话,可以把整个sql的部分放在一个call execute()里面。
你说的丢失end的问题就是因为,sas读到proc sql的时候它以为整个data step结束了。

藤椅
Tigflanker 发表于 2013-3-14 23:50:22
matchlessboy 发表于 2013-3-14 23:38
这里不能直接用proc sql, 如果要用的话,可以把整个sql的部分放在一个call execute()里面。
你说的丢失end ...
你说的地方很正确,就是那,我正在尝试用你的方法解决,感谢。
Bye SAS.
若有缘,能重聚。

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-21 14:32