BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
chandusaladi
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

Check the SAS options (proc options will do this) of your SAS batch environment. You may find the SYNTAXCHECK option is set:

 

http://support.sas.com/documentation/cdl/en/lesysoptsref/68023/HTML/default/viewer.htm#n014qbvh3po8w...

 

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.

View solution in original post

9 REPLIES 9
LinusH
Tourmaline | Level 20
What about providing the log?
Data never sleeps
chandusaladi
Fluorite | Level 6

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.

 

chandusaladi
Fluorite | Level 6

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

Kurt_Bremser
Super User

&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.

SASKiwi
PROC Star

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.

chandusaladi
Fluorite | Level 6
the Current environment doesn't have SAS scheduler license so we are using OS scheduler which don't have capability to send mail alerts
SASKiwi
PROC Star

Check the SAS options (proc options will do this) of your SAS batch environment. You may find the SYNTAXCHECK option is set:

 

http://support.sas.com/documentation/cdl/en/lesysoptsref/68023/HTML/default/viewer.htm#n014qbvh3po8w...

 

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.

chandusaladi
Fluorite | Level 6
Thank you very much.
now its working after changing the options in the batch server

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

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
  • 9 replies
  • 3549 views
  • 1 like
  • 4 in conversation