BookmarkSubscribeRSS Feed
tparvaiz
Obsidian | Level 7

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

1 REPLY 1
Jagadishkatam
Amethyst | Level 16

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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 1 reply
  • 1769 views
  • 0 likes
  • 2 in conversation