BookmarkSubscribeRSS Feed
qd96xuweifeng1
Calcite | Level 5

Hello,

 

Recently, I encounter one problem on email sending. In my code, if there is no error (&syscc. = 0) the email will be sent with error free message. If &syscc. <= 4, the email will be sent with warning message. Otherwise, the email will be sent with error alert message.

 

This code works well on Unix via SAS EG (also run the code on Unix), and I can receive all these three type of messages under different situation. The log of "%f_notice;" for error alert message by SAS EG is below:

379        %f_notice;

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
    
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      
4                                                          The SAS System                            15:07 Thursday, August 25, 2022

NOTE: The file OUTBOX is:
      E-Mail Access Device

Message sent
      To:          "test@test.com"
      Cc:          
      Bcc:         
      Subject:     Test_Code run status for 202207
      Attachments: ( 
"/sasdata/Test_Code.log" CONTENT_TYPE = 
"application/txt" ) 
NOTE: 2 records were written to the file OUTBOX.
      The minimum record length was 66.
      The maximum record length was 141.
NOTE: There were 2 observations read from the data set WORK.BODY_FAIL.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.00 seconds
      
NOTE: Fileref OUTBOX has been deassigned.
380        

 

However, when I run it on Unix via "Tectia - SSH Terminal", both "Error free" and "Warning" messages can be sent successfully, but the message with "Error alert" cannot be sent. The log of "%f_notice;" for error alert message by Unix via "Tectia - SSH Terminal" is below:

354        %f_notice;

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds
      
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds
      
NOTE: Fileref OUTBOX has been deassigned.
355        

The code is included as below. Could anyone please advise on this? Is there any difference on initial options between SAS EG and Unix environment caused this observation?

 

Any suggestion will be appreciated!

 

Thanks,

Wayne

 

data body_Success;
length body $500.;
body = "The code of &report_code. is executed successfully without any issue for &YM_ID..
<br /><br />
Please find the details in the attached log."; output;

body = "<br /><br /><i>This is an automated e-mail. Please do not respond."; output;
run;

data body_Fail;
length body $500.;
body = "The code of &report_code. is failed on &YM_ID. execution.
<br /><br />
Please find the details in the attached log."; output;

body = "<br /><br /><i>This is an automated e-mail. Please do not respond."; output;
run;

data body_Warn;
length body $500.;
body = "The code of &report_code. is successfully executed for &YM_ID., but some warning messages are detected.
<br /><br />
Please find the details in the attached log."; output;

body = "<br /><br /><i>This is an automated e-mail. Please do not respond."; output;
run;


/* Email with XLSX attachments */
%macro EMAIL_XLSX (subject=, body=, to=, from=%str(Automated Process <do.not.reply@test.com>), attach1=, attach2=, attach3=, attach4=, attach5=);
data _null_;
call symput("to", tranwrd(trim(left(%trim("&to."))), " ", ",")); /* space delimited - replace all spaces with comma */
run;
data _null_;
length out $1024;
To = %trim("&to.");
do while (index(To,",")>0);
out = trim(out) || ' "' || trim(substr(To, 1, index(To,",")-1)) || '"';
To = strip(substr(To, index(To,",")+1, length(To)-index(To,",")));
end;
out = trim(out) || ' "' || trim(To) || '"';
out = trim(out);
call symput("To", out);
run;
filename outbox email "do.not.reply@test.com";

data _null_;
file outbox
to=(&to.)
from=("&from.")
sender=("&from.")
subject="&subject."
attach=("&attach1." content_type="application/txt")
type='text/html'
;
set &body.;
put Body;
run;
filename outbox clear;
%mend;

%macro f_notice;
%if &syscc. = 0 %then %do;

%EMAIL_XLSX(
subject=%str(&report_code. monthly run status for &YM_ID.),
body=body_Success,
to= &daily_exrtact_recipients.,
attach1=%str(&report_code_folder.&report_code..log)
);
%end;
%else %if &syscc. <= 4 %then %do;

%EMAIL_XLSX(
subject=%str(&report_code. monthly run status for &YM_ID.),
body=body_Warn,
to= &daily_exrtact_recipients.,
attach1=%str(&report_code_folder.&report_code..log)
);
%end;
%else %do;

%EMAIL_XLSX(
subject=%str(&report_code. monthly run status for &YM_ID.),
body=body_Fail,
to= &daily_exrtact_recipients.,
attach1=%str(&report_code_folder.&report_code..log)
);
%end;

%Mend;

 

3 REPLIES 3
ChrisHemedinger
Community Manager

Is it possible that in that other environment OPTIONS ERRORABEND is set?

 

ERRORABEND System Option

Specifies whether SAS responds to errors by terminating.

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
qd96xuweifeng1
Calcite | Level 5

Hi @ChrisHemedinger ,

 

Thank you so much for your quick response! It is possible, but looks like the code keep running after encountering the first error. Because, in my test code, I have one more data step to create a new table after the error process. The new table can be created successfully.  

 

However, may I know how to cancel the option of "ERRORABEND"? I tried "Options = NOERRORABEND;" at the first beginning of the code, but it still does not work.

 

Thanks,

Wayne

qd96xuweifeng1
Calcite | Level 5

I just checked by %put %sysfunc(getoption(errorabend));, and the value is 'NOERRORABEND'. Therefore, this should not be the root cause. I plan to compare all of options tomorrow to see if there is any difference between my EG and Unix environment.

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 770 views
  • 0 likes
  • 2 in conversation