Desktop productivity for business analysts and programmers

Sending emails from SAS.

Accepted Solution Solved
Reply
Contributor
Posts: 36
Accepted Solution

Sending emails from SAS.

Hi,

I have to send emails from SAS by fetching the data from a data set. I have the mail ids around 5000. Hence I am getting "WARNING: Email service not available". Hence I would like to send the first 200 mails first and hold the process for few seconds and start the process to send 201 to 400 and hold the process for the same few seconds and so on.

My data set looks as follows.

useridmailid
100abc@some.com
101def@some.com
102ghi@some.com
103jkl@some.com
104mno@some.com
105pqr@some.com

All these are unique mail ids.

I am new to SAS and I wrote the code as below..but I am getting "WARNING: Email service not available" becuase of SMTP server timeout or heavy load.

%macro email;

FILENAME file_mail EMAIL LRECL=3200 TYPE='text/html';

     DATA _NULL_;
          SET emails END=EOF;
          BY mailid userid;
          FILE file_mail;

               put '!EM_TO!' mailid;
               put '!EM_SUBJECT!' 'Test Plans have been created.';
               put 'The following test plans have been created with you as a tester.';
               put '<br>';
               link = '<a href="' ||left(strip(userid)) || '">' ||'</a>'
               put '!EM_SEND!';
               put '!EM_NEWMSG!';
                    if EOF then
                         put '!EM_ABORT!';

     RUN;

%mend;
%email;


Accepted Solutions
Solution
‎11-13-2014 07:36 AM
Super Contributor
Posts: 333

Re: Sending emails from SAS.

I think you can skip the counter and use:

if mod(_n_,200) = 0 then sleep(2);

Eric

View solution in original post


All Replies
Esteemed Advisor
Posts: 6,646

Re: Sending emails from SAS.

You could do this in the data step:

retain counter 0;

counter + 1;

if counter = 200 then do;

  counter = 0;

  sleep(2);

end;

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Solution
‎11-13-2014 07:36 AM
Super Contributor
Posts: 333

Re: Sending emails from SAS.

I think you can skip the counter and use:

if mod(_n_,200) = 0 then sleep(2);

Eric

Esteemed Advisor
Posts: 6,646

Re: Sending emails from SAS.

Of course, but calling the mod() function with every iteration may unnecessarily eat CPU cycles. Blame it on the old-school programmer in me Smiley Happy

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 36

Re: Sending emails from SAS.


Thanks for your reply.

Its throwing an error after including the above either of the above two codes in DATA STEO, like

"ERROR: Undeclared array referenced: sleep."

Could you please write the entire code.

Many thanks in advance.

Esteemed Advisor
Posts: 6,646

Re: Sending emails from SAS.

my bad; did some C lately, where one calls a function like a procedure.

use

call sleep(2);

instead of

sleep(2);

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 36

Re: Sending emails from SAS.

: Thanks for the information provided.

Yes you are right ,I am able to send mail a maximum of 499 after that I am getting that ERROR message.

Contributor
Posts: 36

Re: Sending emails from SAS.

: Yeh now its not throwing error. But still I am unable to send the mails after 499 records eventhough I included the call sleep in the data step.

Esteemed Advisor
Posts: 6,646

Re: Sending emails from SAS.

Then it is not a load problem, you most probably are not allowed to send >= 500 emails in one action.

So I'd suggest to split the data set into chunks < 500 and iterate through these with a macro.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 36

Re: Sending emails from SAS.

: Yes you are right. But its related to production.Hence the data will increase gradually and the number of tables also will be increase.

Esteemed Advisor
Posts: 6,646

Re: Sending emails from SAS.

Yes, you need to write the macro in a way to be flexible, so it does do your work for you in the future.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 36

Re: Sending emails from SAS.

: Yes we need to right the macro.

Valued Guide
Posts: 3,206

Re: Sending emails from SAS.

That number of 499 is weird a human setting to be expected at the server side. Is it possible?

- https://itservices.stanford.edu/service/emailcalendar/email/spam/limit  (zimbra)

- Exchange Online Protection Limits | Exchange Online Protection Service Description (number of outbound message send)

The error message should probably not some unexplainable error but one telling a limit like this has been reached

Can you validate this?

---->-- ja karman --<-----
Valued Guide
Posts: 3,206

Re: Sending emails from SAS.

Why not talk to the mail-server administrator, he had control on that number of mails.

---->-- ja karman --<-----
Contributor
Posts: 36

Re: Sending emails from SAS.

: I am not aware like whether the mail-server admin can have the control over the number of mails to be trigger. I need to investigate on this more.

☑ This topic is SOLVED.

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

Discussion stats
  • 15 replies
  • 985 views
  • 6 likes
  • 4 in conversation