BookmarkSubscribeRSS Feed
JordanS
Calcite | Level 5

Hello,

 

I am attempting to email an XLSX file that is created via ODS from a Unix environment, but I am getting two different error messages when trying to open the file in Excel 2013. The first is: "We found a problem with some cotent in 'MY_FILE.xlsx'.Do you want to try to recover as much as we can? If you trust hte source of this workbook, click Yes." After clicking "Yes", I am getting "Excel cannot open the file "MY_FILE.xlsx" becaause the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file."

 

When I download the file via an FTP client directly from the Unix environment, I still get the first message, but after clicking "Yes", Excel can successfully repair the file and I can view the contents. 

 

My SAS version is 9.04 and the code that I am using is below:

<code>

 

ods excel file="/unix/path/MY_FILE.xlsx";


proc report data=libname.my_dataset headline headskip missing;
define product/ width=20 display style(column)={tagattr='Format:TEXT'};
define description/ width=20 display style(column)={tagattr='Format:TEXT'};
define total/ width=20 display style(column)={tagattr='Format:TEXT'};
define sub_total/ width=20 display style(column)={tagattr='Format:TEXT'};
RUN;

ods excel close;
ODS LISTING;

%let attachment = /unix/path/MY_FILE.xlsx;

filename SENDMAIL email TO= "asdf@email.com"
subject= "Email Subject"
type = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
attach= ("&attachment");
run;

DATA _NULL_;
file SENDMAIL;
RUN;

 

</code>

 

 

I have tried defining the content type in several ways, including adding it into the attachment arguments, but that just attempts to attach random files to the email and I still get the same error messages. I have also tried "application/xlsx" and "application/excel" content-types, both with the same results.

 

Any help would be greatly appreciated.

 

Thanks!

 

-Jordan

2 REPLIES 2
Quentin
Super User

I can replicate the problem with:

 

%let attachment=%sysfunc(pathname(work))/MY_FILE.xlsx ;

ods excel file="&attachment";

proc print data=sashelp.class ;
run ;

ods excel close;

filename SENDMAIL email 
  to= "me@blah.com"
  from="me@blah.com"
  subject= "Email Subject"
  attach= ("&attachment") ;
run;

data _null_;
  file SENDMAIL;
run ;
BASUG is hosting free webinars Next up: Mike Sale presenting Data Warehousing with SAS April 10 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
JordanS
Calcite | Level 5

Thanks for the verfication! Glad I'm not the only one. We've created a work around by just zipping the file first and attaching, but I'd rather not have to do that long term. 

 

-Jordan

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
  • 2 replies
  • 1384 views
  • 0 likes
  • 2 in conversation