Hi,
Just wondering if there is an option to send sas logs in LSF if job failed?
I cant see any option to attached logs when setting the e-mail notification.
Thanks,
Unfortunately, from what I see, there is no option to do this. The email notification is pretty basic and it doesn't look like you can customise them.
As far as I know there is no option to send the log as mail attachment. If you want to do it, you need to code something yourself.
Logfiles tend to be big, so it might be better to send a mail with the path/name of the logfile in case of errors, but if you code it yourself, you could also read the current log, write it to a temp file in your working directory and attach that to the email.
The idea is to write a macro with some code to check the current syscc-value in the job. If syscc = 0 (or < 4, if you want to be notified of warnings as well) then send an error mail with the jobname, syscc value and logfile name. Instead of coding the recipient in the macro it could be made dynamic by defining the recipient in an environment variable in your SAS Batch environment.
You can get the jobname and logfile name like this:
%let CurrentJob = %scan(%scan(%sysget(LSB_JOBNAME),4,%str(:)),1,%str({));
%let CurrentLog = %sysfunc(getoption(log));
If your SAS environment is SAS Grid with ARM logging enabled, it needs some more code, because the SAS Log option returns a partial logname without timestamp. I could supply code to circumvent that by getting the start time from OS and search for a log file created within some seconds after start time.
The macro can be called from the autocall libhrary in several ways. If you call the macro in a -TERMST option, it would work without any modification of the jobs, but you need to find the proper place to add the _TERMSTMT option to the SAS call in your batch environment. Depending on the SAS software you use it might be somewhere the server plugin in Management Console.
You could also add the macro call to all jobs. Add a macro call to the end of your job files or - in case of DI Studio jobs - create a user-written transformation with the macro call and add it as the last transformation in all jobs and redeploy the jobs. That would be a lot of work if your jobs are counted in thousands.
We do a similar thing at my work with some 4500 jobs in daily batch, only instead of sending emails, we write runtime information to a data base and have a small application, where we can monitor batch progress and browse log files for all finished jobs.
Agree, I think you have to code this yourself. I have a macro that scans the current log file. If it finds errors/warnings/bad notes, it emails me. It also writes job metadata /status to a database table. So I have a nightly job that checks that table to make sure all expected jobs ran without errors.
Tricia Aanderud has a blog post about how to log-scan end email the results:
https://bi-notes.com/sas-eg-check-the-log/
It's written for EG, but general process works for any SAS job/environment.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.