- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Folks,
I have developed a project for my processing of quiet an intensive workload.
I have broken it into 4 separate programs.
At the very top of my programs I tell SAS to print the log to a specific location.
proc printto log="location\\Parsing_&date..txt";
run;
At the end of the program I have.
proc printto;
run;
What I would like to do is have SAS check these logs and send me an email if it finds an error in them. I have seen this code online. I would like to augment the below to actually pull what the error is too. I would also like to add another condition to check if the code is still running.
So I would have condition 1 - An error occurred 2 - Code is still running 3 - The job ran to completion
Can anyone provide any advice?
%macro send_mail;
filename mymail email 'myemail' subject='Processing';
%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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You do not need to check the log; just use the automatic macro variable &SYSCC. If it's not zero, something went wrong.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Kurt would this still work even if at the top of my program I'm printing the log to an external area??
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The automatic macro variable SYSCC (follow the link) is independent from where the log is written. It contains the exit code that SAS will return to the parent process when it ends. For a run free of WARNINGs and ERRORs, this is 0.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I have a macro written that carries out a procedure n times. I'm printing all from the logs to an external file.
I tried the following and I'm getting email saying an error has occurred. When I examine the log there is no error?
proc printto log="Logs\i..txt";
%macro agg(month,final_data);
*My macro steps;
%mend agg;
%agg(temps.apr_20,pmoda.apr_20);
%macro send_mail;
filename mymail email 'myemail' subject='Processing';
%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
proc printto;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Insert
%put &syscc;
at the beginning of your code to see if you enter it in a clean state.
You can also do
%let syscc = 0;
at the beginning of your code to reset the macro variable if the non-zero code is caused by something in your autoexec. SYSCC is read and write.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Sean_OConnor wrote:
I have a macro written that carries out a procedure n times. I'm printing all from the logs to an external file.
I tried the following and I'm getting email saying an error has occurred. When I examine the log there is no error?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If you want to have the email include the actual error in the body of the message, then I think you might want to parse the log, looking for errors, warnings, and bad notes. It's a non-trivial task, but of course once you have a %logscan() macro that will email you, you can use it everywhere. Also, there are plenty of %logscan macros in papers and blog posts etc.
Here's one I like, and there are more mentioned in the comments:
https://bi-notes.com/sas-eg-check-the-log/
The other option to scanning the log is to just test &syscc, as you are doing, and when you send an email to notify you of an error, attach the log file to the email. Or sometimes you can put a link to the log file in the body of the email, rather than attach it. Even if you do the log scanning and put the error message in the email, nine times out of 10, you end up opening the full log file.
Next up: Troy Martin Hughes presents Calling Open-Source Python Functions within SAS PROC FCMP: A Google Maps API Geocoding Adventure on Wednesday April 23.
Register now at https://www.basug.org/events.