1

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

这可能吗?我正在尝试以下方法,但它不起作用。当 warning=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

4 回答 4

5

您应该能够使用电子邮件指令来中止消息。

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

data _null_;
  file outbox;
  if &warning. then do;
    put "Hello,"
     // "Warning report attached."
     // "Regards,"
      / "Chris"
    ;
  end;
  else put '!EM_ABORT!';
run;
于 2018-06-08T15:57:23.470 回答
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;
于 2018-06-08T14:00:17.993 回答
1

我认为这是因为您不使用then,即使在那里我认为会有语法问题,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.);
于 2018-06-08T14:39:12.867 回答
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,));
于 2018-06-10T16:32:33.357 回答