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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 260 views
  • 0 likes
  • 3 in conversation