BookmarkSubscribeRSS Feed
joshkylepearce1
Calcite | Level 5

I'd like to write code that checks the SAS log for errors/warnings. If there are no errors/warnings throughout the code, I'd like to send an email with the results.

 

I am aware that something similar is possible in SAS Management Console, where an exit code is produced i.e. return code = 0 (success), return code = 1 (warning), return code = 2 (error). In this particular example, I am not working with a batch process, and I'd like to customize the email that is sent to emails, so I'd like to perform this task in SAS Enterprise Guide. Recreating a customized version of the SAS Management Console return codes, and create logic that is only executed if the return code = 0, could be a good solution.

 

I have come across SAS community posts utilizing the syserr & syserrortext macro variables. However, I'm looking for an approach that checks an entire SAS program, as opposed to an error check after each individual data/proc step.

 

Maybe there's a way to read the SAS log file, count the number of occurences of the string 'ERROR:" and "WARNING:", and create a condition where code is performed where errors and warnings are equal to zero. Unfortunately, I couldn't find anything that worked for me online.

 

I'm thinking of something like this:

 

/*Email setup*/
filename outbox email 
from = 'my.email@gmail.com'
to = 'your.email@gmail.com'
subject = "Results"
attach = "C:\temp\results.csv"
;
 
/*Send email if there are no errors/warnings*/
%macro error_check;
%if &number_of_errors. = 0 and &number_of_warnings. = 0 %then %do;
data _null_;
file outbox;
put "Hi,";
put ;
put "Customized message to the relevant stakeholders.";
put ;
put "Thanks,";
put "Josh";
run;
%end;
%mend;
 
%error_check;
3 REPLIES 3
JOL
SAS Employee JOL
SAS Employee

Have you explored the interactive "Send Email as a Step" feature in Enterprise Guide. You must use a Process Flow, right click on program ->

Share -> Email as a step in the project.  Then uncheck option to "Send even when errors occur in the files".  Note the "Add" button on the right in step 1 to choose the type of file you want to send from inside or outside of your project.

You may want to turn on the global Project Log when using this feature.  See relevant screen captures below

    

JOL_0-1718121176575.png

 

 

JOL_1-1718121419327.png

 

JOL_2-1718121803914.png

SAS Help Center: Using the Project Log

 

 

Tom
Super User Tom
Super User

Are you expecting to send the email as part of the same SAS run as the one that you are checking?

 

Or do you plan to write a program that will scan the LOG of a previously run program and then produce the email?

joshkylepearce1
Calcite | Level 5

The former. Currently, if the entire SAS project is run, an email is sent to stakeholders irrespective of whether there are code errors/warnings in earlier sections of the code. The goal is to put a control in place that checks whether any errors/warnings occur, in the same run, and only send the results via email if all code ran without errors/warnings.  

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
  • 3 replies
  • 1029 views
  • 0 likes
  • 3 in conversation