SAS code working properly in Base SAS but not working in Batch mode

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

SAS code working properly in Base SAS but not working in Batch mode

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


Accepted Solutions
Solution
‎11-02-2016 02:37 AM
Super User
Posts: 3,260

Re: SAS code working properly in Base SAS but not working in Batch mode

Posted in reply to chandusaladi

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


All Replies
Super User
Posts: 5,435

Re: SAS code working properly in Base SAS but not working in Batch mode

Posted in reply to chandusaladi
What about providing the log?
Data never sleeps
Occasional Contributor
Posts: 6

Re: SAS code working properly in Base SAS but not working in Batch mode

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.

 

Super User
Posts: 7,844

Re: SAS code working properly in Base SAS but not working in Batch mode

Posted in reply to chandusaladi

That

ERROR:Libref SBA is not assigned

points to a missing libname definition, either through metadata or autoexec.sas.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 6

Re: SAS code working properly in Base SAS but not working in Batch mode

[ Edited ]
Posted in reply to KurtBremser

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

Super User
Posts: 7,844

Re: SAS code working properly in Base SAS but not working in Batch mode

Posted in reply to chandusaladi

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

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 3,260

Re: SAS code working properly in Base SAS but not working in Batch mode

Posted in reply to chandusaladi

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.

Occasional Contributor
Posts: 6

Re: SAS code working properly in Base SAS but not working in Batch mode

the Current environment doesn't have SAS scheduler license so we are using OS scheduler which don't have capability to send mail alerts
Solution
‎11-02-2016 02:37 AM
Super User
Posts: 3,260

Re: SAS code working properly in Base SAS but not working in Batch mode

Posted in reply to chandusaladi

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.

Occasional Contributor
Posts: 6

Re: SAS code working properly in Base SAS but not working in Batch mode

Thank you very much.
now its working after changing the options in the batch server
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 517 views
  • 1 like
  • 4 in conversation