Hi
I am using the following code to generated error messages that occured during the SAS job run
the issue is when i am runnning the code through workspace server/EG it is sending the mail alerts where as when i scheduled it and run through the batch server it is not sending the mail alerts where as "abortcancel" statement is executed which is in the same macro
when an error occurs
PS: SMTP is configured in both workspace and batch mode in similar way
%macro ab_stop;
/* &syserr is a default macro variable which is generated internally in SAS */
%if not (&syserr eq 0 or &syserr eq 4) %then %do;
FILENAME Mailbox EMAIL TO=('XXXX@YYY.com')
CC=('support@yyy.com')
Subject='JOB FAILURE!!!';
DATA _NULL_;
FILE Mailbox;
PUT "job failed due to following error";
PUT "&SYSERRORTEXT";
RUN;
%abort cancel;
%end;
%mend;
proc sql;
create table temp1 as
select *
from sba.cars;
quit;
%ab_stop;
proc sql;
create table temp2 as
select *
from sashelp.cars;
quit;
%ab_stop;
Thanks inadvance
Check the SAS options (proc options will do this) of your SAS batch environment. You may find the SYNTAXCHECK option is set:
If this is the case then the option OBS = 0 will be set as soon as the SAS error occurs, hence your email DATA step will not produce any output. Try NOSYNTAXCHECK to see if this fixes the problem.
Following is the log when i run the program through Batch server
/* Macro to abort code at that particular step in case of an error and send to the Error*/
64
65 %macro ab_stop;
66 /* &syserr is a default macro variable which is generated internally in SAS */
67 %if not (&syserr eq 0 or &syserr eq 4) %then %do;
68 FILENAME Mailbox EMAIL TO=('XXX@YYY.com')
71 CC=('xxxx@yyy.com'
72 'xxx@yyy.com')
73 Subject='JOB FAILURE!!!';
74 DATA _NULL_;
75 FILE Mailbox;
4 The SAS System 10:00 Monday, October 31, 2016
76 PUT "job failed due to following error";
77 PUT "&SYSERRORTEXT";
78 RUN;
79 %abort cancel;
80 %end;
81 %mend;
82
proc sql;
create table temp1 as
select *
from sba.cars;
quit;
ERROR:Libref SBA is not assigned.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: SAS set option OBS=0 and will continue to check statements. This might cause NOTE: No observations in data set.
NOTE: MVA_DSIO.OPEN_CLOSE| _DISARM| STOP| _DISARM| 2016-10-31T11:05:00,601-04:00| _DISARM| BatchServer| _DISARM| SAS| _DISARM| | _DISARM| 4529429| _DISARM| 14323712| _DISARM| 12| _DISARM| 13| _DISARM| 0| _DISARM| 40190216| _DISARM| 0.000000| _DISARM| 0.000460| _DISARM| 1793545500.601018| _DISARM| 1793545500.601478| _DISARM| 0.000000| _DISARM| | _ENDDISARM
NOTE: PROCEDURE| _DISARM| STOP| _DISARM| 2016-10-31T11:05:00,601-04:00| _DISARM| BatchServer| _DISARM| SAS| _DISARM| | _DISARM| 19574784| _DISARM| 14323712| _DISARM| 12| _DISARM| 13| _DISARM| 0| _DISARM| 40190216| _DISARM| 0.000000| _DISARM| 0.001256| _DISARM| 1793545500.600375| _DISARM| 1793545500.601631| _DISARM| 0.000000| _DISARM| | _ENDDISARM
176 %ab_stop;
NOTE: PROCEDURE| _DISARM| STOP| _DISARM| 2016-10-31T11:05:00,604-04:00| _DISARM| BatchServer| _DISARM| SAS| _DISARM| | _DISARM| 19574784| _DISARM| 14323712| _DISARM| 12| _DISARM| 13| _DISARM| 0| _DISARM| 40190216| _DISARM| 0.000000| _DISARM| 0.002365| _DISARM| 1793545500.602433| _DISARM| 1793545500.604798| _DISARM| 0.000000| _DISARM| | _ENDDISARM
NOTE: PROCEDURE SQL used ( (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
ERROR: Execution canceled by an %ABORT CANCEL statement.
NOTE: The SAS System stopped processing due to receiving a CANCEL request.
That
ERROR:Libref SBA is not assigned
points to a missing libname definition, either through metadata or autoexec.sas.
Main purpose of my code is to send the mail alerts when there is an error in the code. here is the error "Libref SBA is not assigned" so it should send the mail and then abort the program. but it is not sending the mail where as the statement that placed after mail statement "abort cancel" statement is executed , even though the statement is in the same macro as mail statement
&syserr is reset at every step boundary, so a successful step in between will prevent your error detection. I'd rather use &syscc for this.
And I see that you want to tolerate WARNINGs. I consider that a VERY BAD IDEA. Programs that do not always end with a return code of zero when they run "successfully" point to sloppy programming and are in dire need of debugging.
How are you running your batch jobs? If you are using a scheduler, then it can usually email you if a job fails so no coding is required. That is what we do and it is simple and reliable.
Check the SAS options (proc options will do this) of your SAS batch environment. You may find the SYNTAXCHECK option is set:
If this is the case then the option OBS = 0 will be set as soon as the SAS error occurs, hence your email DATA step will not produce any output. Try NOSYNTAXCHECK to see if this fixes the problem.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.