仅在满足特定条件时才从SAS发送电子邮件

时间:2018-06-08 13:27:04

标签: sas enterprise-guide proc-report

我希望SAS发送电子邮件,但前提是全局宏变量& warning等于1。

这可能吗?我正在尝试以下方法,但它不起作用。警告= 0时,它仍会发送电子邮件。

filename outbox email
               to=('me@myemail.com')
               subject='Warning Report'
               from='you@myemail.com'
               attach='/report.html';

DATA _null_;
file outbox;
Put "Hello,"//
"Warning report attached."//
"Regards,"/
"Chris";
if &warning. =1
run;

4 个答案:

答案 0 :(得分:5)

您应该可以使用电子邮件指令来中止邮件。

  

!EM_ABORT!停止当前消息。您可以使用此指令   停止SAS软件在结束时自动发送消息   数据步骤。

data _null_;
  file outbox;
  if &warning. then do;
    put "Hello,"
     // "Warning report attached."
     // "Regards,"
      / "Chris"
    ;
  end;
  else put '!EM_ABORT!';
run;

答案 1 :(得分:1)

试试这个:

  %let warning=1;

  %macro send();
  %if &warning. =1 %then %do;
   filename outbox email
           to=('myemail@mail.com')
           subject='Warning Report'
           from='you@myemail.com'
           ;

  DATA _null_;
  file outbox;
  Put "Hello,"//
  "Warning report attached."//
  "Regards,"/
  "Chris";
  run;
  %end;
  %mend;

  %send;

答案 2 :(得分:1)

我认为这是因为您不使用然后,即使在那里我认为会出现语法问题,SAS也无法完成该代码块或返回错误.... 你可以把它放在一个宏中,它会起作用。

尝试这样的事情

%macro email(condition=);

%if &condition.=1 %then %do;
filename outbox email
               to=('me@myemail.com')
               subject='Warning Report'
               from='you@myemail.com'
               attach='/report.html';

DATA _null_;
file outbox;
Put "Hello,";
Put "Warning report attached.";
Put "Regards,";
Put "Chris";
run;
%end;
%mend;
%email(condition=&warning.);

答案 3 :(得分:0)

您无法在步骤中基于if表达式有条件地运行步骤。

您可以继续使用开放式代码STEP并有条理地将RUN语句修改为RUN CANCEL,并明智地使用%sysfunc(ifc。 “好处”是您不需要将逻辑嵌入到单独的宏中。

%let warning = 0;
data _null_;
  put "NOTE: macro symbol 'warning' is &warning";
run %sysfunc(ifc(&warning,CANCEL,));

%let warning = 1;
data _null_;
  %* never executed because step is cancelled;
  put "NOTE: macro symbol 'warning' is &warning";
run %sysfunc(ifc(&warning,CANCEL,));