1

I want SAS to send an email out, but only if a global macro variable &warning is equal to 1.

Is this possible? I'm trying the following, but it's not working. It still sends an email when 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 Answers4

5

You should be able to use email directives to abort the message.

!EM_ABORT! stops the current message. You can use this directive to stop SAS software from automatically sending the message at the end of the DATA step.

data _null_;
  file outbox;
  if &warning. then do;
    put "Hello,"
     // "Warning report attached."
     // "Regards,"
      / "Chris"
    ;
  end;
  else put '!EM_ABORT!';
run;
Tom
  • 47,574
  • 2
  • 16
  • 29
1

Try this:

  %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;
John Doe
  • 596
  • 5
  • 8
1

I think it's because you don't use then, even thereI think there will be a syntax issue and SAS will not be able to finish that code block or return an error.... You can put it in a macro and it will work.

try something like this

%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.);
Wired604
  • 370
  • 1
  • 3
  • 10
0

You can not conditionally run a step based on a if expression within the step.

You could continue to have an open-code STEP and conditionally modify the RUN statement to become RUN CANCEL with a judicious use of %sysfunc(ifc. The 'benefit' being you don't need to embed the logic within a separate macro.

%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,));
Richard
  • 25,390
  • 3
  • 25
  • 38