When I'm running below code in EG it is working fine [Abort Job and send error to mail id] but when same Program I'm running thru Unix SAS Grid it is not sending mail, Please help me out.. Thanks
Test_mail.sas :
%macro errmail;
;run;quit;
%if %eval(&syserr > 4) %then
%do;
data _null_;
filename myfile email
to=("email_id@chk.com")
subject= "Subject Line_Test "
type="text/plain";
file myfile;
put 'Your job received the following ERROR/WARNING message:';
put;
put 'ERROR was:';
put "&syserrortext";
put;
put 'WARNING was:';
put "&syswarningtext";
run;
%abort cancel;
%end;
%mend errmail;
data ds1;
set ds2;
%errmail;
Below Command I'm using on Unix SAS Grid :
sasgsub -gridwait -gridsubmitpgm test_mail.sas
Above command runs and abort the sas program which I want but not sending mail, as EG sending me the mail.
Make sure that all grid members have email correctly set up. Write a short program that sends email without aborting, run that in batch, and look at the log.
Thanks Kurt for replying, I'm able to send mail thru Unix without aborting statement, how can I send mail with abort statement as it is working in EG.
%macro errmail;
data _null_;
filename myfile email
to=("mail_id")
subject= "subject "
type="text/plain";
file myfile;
put 'Your job received the following ERROR/WARNING message:';
put;
put 'ERROR was:';
put "check2";
put;
put 'WARNING was:';
put "check1";
run;
%mend errmail;
%errmail;
I have the suspicion that your use of %abort cancel is the reason.
In batch mode, %abort cancel causes an immediate termination of the SAS job; since sending mail requires that SAS start an external command to hand the mail over to, the premature termination of SAS might cause this action to not be performed IMO.
(in workspace server mode, the SAS session is not terminated, only the submitted code)
Have you tried to explicitly close the file?
%macro errmail;
;run;quit;
%if %eval(&syserr > 4)
%then %do;
filename myfile email
to=("email_id@chk.com")
subject= "Subject Line_Test "
type="text/plain"
;
data _null_;
file myfile;
put 'Your job received the following ERROR/WARNING message:';
put;
put 'ERROR was:';
put "&syserrortext";
put;
put 'WARNING was:';
put "&syswarningtext";
run;
filename myfile clear;
data _null_;
abort cancel;
run;
%end;
%mend errmail;
data ds1;
set ds2;
%errmail;
Thanks but this also not working, when I'm running " only %errmail; then it is sending me mail from unix (after removing condition). but not sending me mail from unix when I put condition in it (&syserr).. In EG working fine.
I don't know what is happening 😞
%errmail;
"
Run the batch job and use %put to reveal the contents of &syserr at the relevant stages; it might be that you get a value of 3 instead of the expected > 4.
From the documentation:
http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a002592796.htm
"You can send electronic mail programmatically from SAS using the SMTP (Simple Mail Transfer Protocol) e-mail interface. SMTP is available for all operating environments in which SAS runs. To send SMTP e-mail with SAS e-mail support, you must have an intranet or Internet connection that supports SMTP."
So I would say without any information that you are missing something on the Unix system. Consult with your IT, perhaps its just a permission, perhaps they need to make something available.
Thanks RW9,
I'm able to send mail thru SAS Code from Unix but in this particular case I'm not getting mail, although that code is perfectly fine in SAS EG.
Ensure that all EMAIL* options are set either in your program or in the autoexec for each grid session -- naming EMAILHOST, port, etc...
options emailhost='mailserver.company.com' emailsys=smtp;
It might be that when running in the grid, these aren't initialized and are resorting to the default settings.
below macro is sending the mail from grid, but not the one I had issue and on EG it is working find.
%macro errmail;
data _null_;
filename myfile email
to=("mailid")
subject= "test_subj "
type="text/plain";
file myfile;
put 'Your job received the following ERROR/WARNING message:';
put;
put 'ERROR was:';
put "check2";
put;
put 'WARNING was:';
put "check1";
run;
%mend errmail;
%errmail;
Run this code to check your e-mail options:
proc options group=email; run;
Check this within your EG environment and within your server/batch environment -- compare the results and see if you might need to explicitly set some of the EMAIL* options to make it work the way you need.
Did anyone know the solution for this?
We had the same issue. Check your CFG file.
We found our email settings were missing from the cfg file that the sas executable the batch job using.
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!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.