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:
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
SAS Help Center: Using the Project Log
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?
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.
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.
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.
Ready to level-up your skills? Choose your own adventure.