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.

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!

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.

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
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.

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
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.

sas-innovate-white.png

Special offer for SAS Communities members

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.

 

View the full agenda.

Register 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
  • 1434 views
  • 3 likes
  • 3 in conversation