Sas 在打开代码中与%if%然后%do一起使用时,“中止取消”会导致错误
我们运行了一个main函数,它调用了很多helper语法,所有的东西都是在Sas 在打开代码中与%if%然后%do一起使用时,“中止取消”会导致错误,sas,Sas,我们运行了一个main函数,它调用了很多helper语法,所有的东西都是在比如SAS中以交互方式运行的。通常一次运行需要30分钟左右,因此当数据出现错误时,最好停止整个任务。为此,我们在主函数中有一些条件的if-then语句,它们位于opencode(取决于年份)中,并且stop通过abort-cancel语句完成 它看起来像这样MWE: %let year = 2020; %if &year. = 2020 %then %do; data test; x = 1; /*some con
比如SAS
中以交互方式运行的。通常一次运行需要30分钟左右,因此当数据出现错误时,最好停止整个任务。为此,我们在主函数中有一些条件的if-then
语句,它们位于opencode
(取决于年份)中,并且stop
通过abort-cancel
语句完成
它看起来像这样MWE:
%let year = 2020;
%if &year. = 2020 %then %do;
data test;
x = 1; /*some condition which puts x = 1 if needed;*/
if x=1 then do;
put "There is an error, please check xy.";
abort cancel;
/*%end;*/
end;
run;
%end;
除了第二次运行此代码段(或任何包含%的开放代码
段,如果%then
)之外,这与预期的一样,我们将得到两个额外的错误(非预期的)
这是有道理的,因为原始的%if%then%do
从未以%end
语句结束。
有趣的是,这可以通过将%end
添加到数据测试中来“修复”
当这个黑客程序运行时,我想知道它是否破坏了其他任何东西,或者是否有更好的解决方案。有什么想法吗?我不确定黄金时段中止取消的准备情况。如果通过%INCLUDE执行“助手文件”,则会有中止文件选项
如果代码如此复杂,那么创建宏可能是值得的。然后,您可以使用宏代码跳过部分代码,而不会导致未执行的开放代码%END问题
%macro mystuff ;
%let status=OK;
....
%if &year. = 2020 %then %do;
data test;
x = 1; /*some condition which puts x = 1 if needed;*/
if x=1 then do;
put "There is an error, please check xy.";
call symputx('status','XY');
abort ;
end;
run;
%end;
%if "&status" ne "OK" %then %goto exit;
... another step that might change STATUS ...
%if "&status" ne "OK" %then %goto exit;
%exit:
%put &=status;
%mend ;
谢谢你,汤姆!是的,大部分内容是通过%include
逐步添加的。我将尝试一下中止文件
,但可能您是对的,我们应该将所有内容都包装在宏中。我只是惊讶于添加一个%end
是“有效的”,但我想这只是一个不一致的问题。哪个%end
是你的黑客?运行之后的那一个
还是注释中的那一个?注释中的那一个,至少在我看来,它完全被替换了。Ofc我需要它在之前取消注释它。很奇怪。
%macro mystuff ;
%let status=OK;
....
%if &year. = 2020 %then %do;
data test;
x = 1; /*some condition which puts x = 1 if needed;*/
if x=1 then do;
put "There is an error, please check xy.";
call symputx('status','XY');
abort ;
end;
run;
%end;
%if "&status" ne "OK" %then %goto exit;
... another step that might change STATUS ...
%if "&status" ne "OK" %then %goto exit;
%exit:
%put &=status;
%mend ;