06-19-2016 08:46 PM
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.
06-19-2016 09:09 PM
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.
06-19-2016 09:12 PM
06-19-2016 09:24 PM
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.
06-20-2016 04:36 AM
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.
06-19-2016 09:38 PM
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.