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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.