DATA Step, Macro, Functions and more

how to send email to recipients that are stored in a table

Reply
Frequent Contributor
Posts: 134

how to send email to recipients that are stored in a table

Hi,

 

I want to send emails to multiple recepients (with attachments) using the email addresses that are stored in the data set. Following is the code that I've used and the error message that I am getting.. please advise

 

 

---------------------CODE that I used - --------------------------------------------------

 

 

data TBL_EMAIL;
input
nuid $ 1-7
email_address $ 9-28
report_id $ 32-33
objectname $ 34-47
objecttype $ 49-64;
cards;
A111111 myemail@Domain.com 1 test report report
A111112 myemail@Domain.com 2 test report report
;
run;

 

%macro email(emailid);
FILENAME Mailbox EMAIL "&emailid"
Subject='Report - Ran okay'
ATTACH="M:\Monthly\Report.xlsx";
DATA _NULL_;
FILE Mailbox;
PUT "Hello";
PUT "Please find the Report as an attachment";
PUT "Thank you";
PUT " ";
RUN;
%mend email;


%macro email_error;
FILENAME Mailbox EMAIL 'xx@yy.com'
Subject='Report - Error' ;
DATA _NULL_;
FILE Mailbox;
PUT "Hello";
PUT "Please be advised that Report was generated with potential errors";
PUT "Thank you";
PUT " ";
RUN;
%mend email_error;

 

data Table2a_;
set Table2(where = (
report_id = 14
) );
if 180000 <= price <= 300000
then call execute ('data _null_; set TBL_EMAIL; where report_id=1; %email('||email_address||'); run;');
else call execute ('%email_error');
run;

 

 

----------------Error Message that I got ------------------------

 

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

ERROR: Invalid E-mail recipient.

 

-----------------------What worked ------------------------------

 

Following code worked (suggesting that there is something wrong in a way I am calling the email macro)

 

data Table2a_;
set Table2(where = (
location_ID = 14 
) );
if 180000 <= price <= 300000 
then call execute ('%email(myemail@Domain.com)');
else call execute ('%email_error');
run;

 

 

 

Thanks

Trusted Advisor
Posts: 1,137

Re: how to send email to recipients that are stored in a table

Could you please share the log with the exact error message you are getting

 

also please try this , I am expecting that in the dataset you are passing you have the email_address variable with emailid's.

 

data Table2a_;
set Table2(where = (
location_ID = 14 
) );
if 180000 <= price <= 300000 
then call execute ('%email('||email_address||')');
else call execute ('%email_error');
run;
Thanks,
Jag
Ask a Question
Discussion stats
  • 1 reply
  • 81 views
  • 0 likes
  • 2 in conversation