Sending emails from SAS if there was an error

Reply
Occasional Contributor
Posts: 6

Sending emails from SAS if there was an error

Hi Everyone, 

 

I am trying to have SAS send out an email to certian stakeholders if the program fails due to an ERROR in the code, prefereable by looking through the log. The main caveat that I have is that I want it to ignore if there was a WARNING in the log. 

 

Im Currently running: 

 

data _null_;
if  &norecords > 0 then do;  
   call symput('send_email',1);
    stop; 
  end;
run;

%macro send_email2;
  %if &send_email eq 0  %then %do;
    data _null_;
      file Emailf ;
      put "No data in today's file - Something has Failed.";
    run;
  %end;
%mend;

but there are way too many opportunities for errors to arise to not be found in the end result. 

 

I would appreciate any help. 

 

THanks, 

Grand Advisor
Posts: 17,360

Re: Sending emails from SAS if there was an error


T1Nukes wrote:

there are way too many opportunities for errors to arise to not be found in the end result. 

 


 

What do you mean by that?

 

Although you can scan the log, in my opinion, it's best to put in some manual checks along the way, and if one of these fails then a flag or error variable is set. 

 

 

Occasional Contributor
Posts: 6

Re: Sending emails from SAS if there was an error

Oh what I mean, is that there are left joins in my code. and if the file Im joining doesnt exist, the output is still created.

How would you suggest adding manual checks?
Grand Advisor
Posts: 17,360

Re: Sending emails from SAS if there was an error

The checks depend on the code. It might be checking a table was created or it may be checking all values in a table are within a certain range. 

 

If if a table doesn't exist in a left join you should get an error? Or do you mean a value in the table? If it's the second that's where you'd add a check to see if you have missing values for some variable. 

Esteemed Advisor
Esteemed Advisor
Posts: 7,217

Re: Sending emails from SAS if there was an error

Why are you writing code that doesn not work half the time?  This is your problem.  You should be writing robust, clean, and readable code.  Once you have that then there shouldn't be a need to scan logs - any problems encountered would be pulled out in your code.

Respected Advisor
Posts: 3,063

Re: Sending emails from SAS if there was an error

Personally I find it way easier to use a job scheduler to send emails if the return code on a SAS job is not 0. That way you pick up most problems without any extra coding. Any SAS error or warning will set the return code > 0.

 

It does mean setting up your SAS programs to run in batch mode but SAS Management Console contains the functionality to do that.

Ask a Question
Discussion stats
  • 5 replies
  • 279 views
  • 2 likes
  • 4 in conversation