BookmarkSubscribeRSS Feed
Harin_Jay
Calcite | Level 5

Hi 

 

When i use the below code to attach a file into a mail body and send , the mail attached excel cannot be open , says its corrupted. i use a %MACRO sendMail(error=); to send the mail via SAS

 

%let attach ='/xxxdata/xxxx/xxxxr/xxx/xxx/xxx/abc_qa.xlsx' (content_type="application/xlsx");

2 REPLIES 2
ballardw
Super User

I'm afraid you will need to share a lot more detail. Such a possibly the entire code for that macro and how you create the Excel file.

 

Did you attempt to verify that the file was readable before you attached it to the email?

 

One very likely scenario that causes this error is that however you create the xlsx file still is connected to the file so it is 'locked' and could not actually be attached.

Harin_Jay
Calcite | Level 5

Hope this helps 

 

 

PROC EXPORT DATA= CPD_PD
OUTFILE= "/xxx/xxx/user/xxx/xxxx/xxxx/CPD_PD"
DBMS=xlsx REPLACE;
SHEET=xoxoxo;
RUN;


%MACRO sendMail(error=);

%LET tolist='vidia@.com'
%LET cclist='harin.jay@com';
%LET sender=sassrv;
%LET subject=Due dates;
%let attach ='/sasdata/xxx/user/xxxx/xxxxL/xxxxxx/CPD_PD.xlsx' (content_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");

PROC SQL NOPRINT;
create table myemail (c varchar(228));
insert into myemail values ("Dear All,");
insert into myemail values ("");
insert into myemail values ("The  dates of the future ");
insert into myemail values ("");
insert into myemail values ("");
insert into myemail values ("Best Regards,");
insert into myemail values (" Team");
insert into myemail values ("");
insert into myemail values ("");
insert into myemail values ("");
insert into myemail values ("************ ************");
QUIT;

 

%PUT NOTE: &tolist;
%PUT NOTE: &cclist;
%PUT NOTE: &sender;
%PUT NOTE: &subject;
%PUT NOTE: &attach;

FILENAME tmpcode TEMP;
DATA _NULL_;
FILE tmpcode MOD;

PUT '%ccrSendEmail(SenderID=';
PUT "&sender,";
PUT "To=&tolist,";
PUT "CC=&cclist,";
PUT "attach=&attach,";
PUT "Subject='&subject');";
RUN;

%INC tmpcode;
%PUT NOTE: email sent;
%MEND sendMail;
%MACRO Main();
%sendmail();
%MEND Main;
%Main();

%put job end execution at %sysfunc(time(),timeampm.) on %sysfunc(date(),worddate.);

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2 replies
  • 682 views
  • 1 like
  • 2 in conversation