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.);

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

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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