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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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