Hi,
I need to send an email to some body about the status of the main SAS code execution, such that if any error occurs, it send an email and inform that. I used the following macro at the end of my code:
%macro send_mail;
filename mymail email 'ABC@gmail.com' subject='Status';
%if &syscc>0 %then %do;
data _null_;
file mymail;
put 'An ERROR has occurred in the code';
run;
%end;
%else %do;
data _null_;
file mymail;
put 'The job ran to completion';
run;
%end;
%mend;
%send_mail
However, it sends an error email (An ERROR has occurred in the code) even when there is no error in the main body of my code. Can you please let me know why it happens and how to resolve it?
Thanks.
Do you have any WARNINGs in the log? SYSCC is set to 4 when there is a warning. So if you want to flag just errors, try >4 for a check.
Do you have any WARNINGs in the log? SYSCC is set to 4 when there is a warning. So if you want to flag just errors, try >4 for a check.
Yes, for example see https://support.sas.com/kb/35/553.html.
But I agree with @Kurt_Bremser -- you should resolve the warnings too to avoid issues. Sometimes warnings are an indicator of a problem that could cause unexpected results, even if not a SAS error.
The only thing you need to change is this:
put 'An ERROR has occurred in the code';
to this:
put 'An ERROR or WARNING has occurred in the code';
Any run that ends with SYSCC ne 0 is not acceptable, and the code needs to be fixed, or any other cause (e.g. wrong input data, wrong time to start the code etc) straightened out.
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.