BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sun538
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

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.

Become an Explorer! Join SAS Analytics Explorers to learn and complete challenges that earn rewards!

View solution in original post

4 REPLIES 4
ChrisHemedinger
Community Manager

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.

Become an Explorer! Join SAS Analytics Explorers to learn and complete challenges that earn rewards!
sun538
Obsidian | Level 7
Many Thanks Chris. Yes, I have some warnings in the log. I changed it to &SYSCC >4 and works fine. Great. Thank you. So, there is no error type that set SYSCC a number between 0 and 4, is that correct?
ChrisHemedinger
Community Manager

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.

Become an Explorer! Join SAS Analytics Explorers to learn and complete challenges that earn rewards!
Kurt_Bremser
Super User

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.

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

Explore Now →
Creating Custom Steps in SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 2572 views
  • 3 likes
  • 3 in conversation