有条件地终止 SAS [英] Conditionally terminate SAS

查看:66
本文介绍了有条件地终止 SAS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果满足特定条件,我将尝试停止 SAS 程序的处理.我创建了一个宏变量,如果该变量 > 0.5,那么我想要程序的硬停止.

I am trying to stop the processing of a SAS program if a certain condition has been met. I have a macro variable created and if that variable is > 0.5 then I want a hard stop of the program.

当前程序看起来像

data a1;
set Server.a2;
run;

%macro1(a1);

%macro2(_t1); /* _t1 generated from %macro1.

data _null_;
if %stopit(_t2) > 0.5 then `?????`; /* _t2 generated from %macro2.

run;

%macro3;

%macro4;

如果 %macro(_t2) >0.5,我想停止整个程序而不运行其余的(%macro3 和 %macro4)

If %macro(_t2) > 0.5, I want to stop of whole program without running the rest (%macro3 and %macro4)

推荐答案

就我个人而言,我倾向于总是使用 abort cancel;(或 %abort cancel;),因为它提供以交互模式和批处理模式运行时的灵活性.

Personally I tend to always use abort cancel; (or %abort cancel;) as it offers flexibility when running in interactive mode and in batch mode.

它只会以交互方式取消提交的代码(但让您的会话保持打开状态).

Interactively it will just cancel the submitted code (but leave your session open).

在批处理模式下,它将停止整个工作.

In batch mode it will stop the entire job.

还有其他选项.您可以在文档中找到完整列表 这里.

There are additional options as well. You can find a full list in the documentation here.

还有 endsas 命令,但我不喜欢它,因为它会关闭当前的交互式会话(并且有条件地执行更困难).

There's also the endsas command but I don't like that as it closes the current interactive session (and it's more difficult to execute conditionally).

这是一个例子:

%let x = 1;

data _null_;
  if &x then abort cancel;
  put "This won't print";
run;

%put This won't print either;

日志中的结果将显示:

ERROR: Execution terminated by an ABORT CANCEL statement at line 4 column 14.
_ERROR_=1 _N_=1

这篇关于有条件地终止 SAS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆