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

Hi,

My mails data set looks as follows

1abc123@some.com
2def@some.com
3ghi@some.com
4jkl@some.com
5abc123@some.com
6def@some.com
7def@some.com

consider abc123@some.com is a wrong email

As of now my code looks as follows;;;

STEP=1: Sorting the data set.

--------------------------------------------------------------------------------------------------------------------

PROC SORT DATA=mails;

BY mail_id;

RUN;

-----------------------------------------------------------------------------------------------------------------------------------

STEP=2 : Sending mails for every three hundred users after holding the triggering mails process for 2 mnts..

---------------------------------------------------------------------------------------------------------------------------------------


%macro send_email;

filename hm_mail email lrecl=32000 type='text/html';


data _null_;   
set mails END=EOF;
by mail_id;
file hm_mail;


retain numofusers 0;

if first.mail_id then do; 

     numofusers=numofusers+1;
  If mod(numofusers,300) = 0 then Timer=Sleep(120,1);

  put '!EM_TO!' mail_id;
  put '!EM_SUBJECT!' 'Test Plans have been created.';
  put 'The following test plans have been created with you as a tester.';
  put '<br>';
end;

id_link = '<a href="' ||left(strip(id)) || '">' || left(strip(id)) || '</a>' ;
put '<br>';
put id_link;
put '<br>';

if last.mail_id then do;
  put '<br>';
  put 'This is a system-generated message. Do not reply to this e-mail.';
  put '!EM_SEND!';
  put '!EM_NEWMSG!';
end;

if EOF then put '!EM_ABORT!';


run;

%mend send_email;
%send_email;

Here I am getting an error message as below when %send_email is excecuted

***********Below is the error message in email logs******************************************************

WARNING: Email: 550 5.1.1 <abc123@some.com Recipient address rejected: User unknown

WARNING: Bad email address: abc123@some.com

ERROR: No email addresses specified.

FATAL: Unrecoverable I/O error detected in the execution of the DATA step program.  Aborted during the EXECUTION phase.

**************************************************************************************************************

After this its not sending emails to the remaining users..

Could you please suggest me how to add an exception to handle this error at the time of exection..

Many thanks in advance..

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Modify your macro so that it sends a single mail:

%macro send_email(recipient);

.....

set mails (where=(mail_id="&recipient")) end=EOF;

(use if _n_ = 1 instead of if first.mail_id)

......

run;

%let syscc=0;

options obs=max;

%mend;

Then do;

proc sort data=mails (keep=mail_id) out=mails_help nodupkey;

by mail_id;

run;

data _null_;

set mails_help;

comstr = '%send_email('!!trim(mail_id)!!');';

call execute(comstr);

run;

(untested, so you may have to do some corrections)

The %let syscc=0; and options obs=max; reset any condition caused by a data step error, may be unnecessary.

View solution in original post

5 REPLIES 5
Kurt_Bremser
Super User

Unless you want to split the process so that every mail address is handled in a single data step, you will have to weed out the invalid mail ID's. The I/O error caused by the faulty email address stops the data step for good.

With separate data steps, you could reset %let syscc=0; and options obs=max; in between.

K_HARI__PRASAD
Calcite | Level 5

Thanks for your reply.

We are unable to find the invalid email ids before sending the emails. While execution time only we are coming to know that the mail id is incorrect and it is causing to terminate the data step.

As you replied, Could you please write the code by including

%let syscc=0; and options obs=max;

Kurt_Bremser
Super User

Modify your macro so that it sends a single mail:

%macro send_email(recipient);

.....

set mails (where=(mail_id="&recipient")) end=EOF;

(use if _n_ = 1 instead of if first.mail_id)

......

run;

%let syscc=0;

options obs=max;

%mend;

Then do;

proc sort data=mails (keep=mail_id) out=mails_help nodupkey;

by mail_id;

run;

data _null_;

set mails_help;

comstr = '%send_email('!!trim(mail_id)!!');';

call execute(comstr);

run;

(untested, so you may have to do some corrections)

The %let syscc=0; and options obs=max; reset any condition caused by a data step error, may be unnecessary.

K_HARI__PRASAD
Calcite | Level 5

Thanks Smiley Happy

DaveBirch
Obsidian | Level 7

I don't think it is the Bad or unknown email address that is causing your program to terminate the data step - these are only Warnings.  The real problem is indicated by "ERROR: No email addresses specified" - i.e. the email process thinks it doesn't have an email address to process, not just a bad email address.

I think this may be caused by:

if last.mail_id then do;

  ...

  put '!EM_NEWMSG!';

end;

which I think would initiate an email message without an EM_TO when the final row in the mails dataset is reached.

I've often had Bad or unknown email addresses, and they've never caused my SAS programs to crash.  But, in my case, the email process has always been asynchronous - usually through SMTP.

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!

SAS Enterprise Guide vs. SAS Studio

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.

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
  • 5 replies
  • 3802 views
  • 0 likes
  • 3 in conversation