The SAS Output Delivery System and reporting techniques

Why SAS email attachment works for CSV file but not xlsx?

Reply
Occasional Contributor
Posts: 5

Why SAS email attachment works for CSV file but not xlsx?

Yesterday I tried to attach a file in email via SAS the first time, but the weird thing was, it worked fine if I attached the CSV file, but if I tried to attach a xlsx file, the attachment in email couldn't be opened.

I then clicked on the attached file, it said "Excel found unreadable content in "filename.xlsx". Do you want to recover the contents of this workbook? If you trust the source of this workbook, click yes."

Then I clicked on yes, it showed another error message "Excel cannot open the file "filename.xlsx" because the file format or the file extension is not valid. Verify that the file has not been corrupted and the the file extension matches the format of the file."

I checked the xlsx file, it looked all good and could be opened on local computer without question. Does anybody know what could cause the issue? Thanks!

filename outmail email 'xxxx@xxxxxx.COM'

                      subject="xxxxxxxxxxxxx"

                      attach="/xxx/xxxx/xxxx.xlsx";

Grand Advisor
Posts: 9,748

Re: Why SAS email attachment works for CSV file but not xlsx?

The issue may be with how the xlsx file was created. If created in SAS provide example code.

Occasional Contributor
Posts: 5

Re: Why SAS email attachment works for CSV file but not xlsx?

 

proc export data=outlib.test outfile="test.xlsx"

dbms=xlsx replace;

sheet="Data";

run;

Respected Advisor
Posts: 2,918

Re: Why SAS email attachment works for CSV file but not xlsx?

With Excel you need to add this to your FILENAME:

content_type="application/xlsx"

Occasional Contributor
Posts: 5

Re: Why SAS email attachment works for CSV file but not xlsx?

Thanks SASKiwi. I added content_type as you suggested but failed with the same error again.

Respected Advisor
Posts: 2,918

Re: Why SAS email attachment works for CSV file but not xlsx?

Try this, perhaps ordering is required. This works for me.

attach=("Spreadsheet.xlsx"  content_type="application/xlsx")

Occasional Contributor
Posts: 5

Re: Why SAS email attachment works for CSV file but not xlsx?

Yeah it works now!!! So excited! Thanks a million SASKiwi!

New User
Posts: 1

Re: Why SAS email attachment works for CSV file but not xlsx?

Thank you SO much.  Just used this with a file created with the new ODS excel destination.

New Contributor
Posts: 3

Re: Why SAS email attachment works for CSV file but not xlsx?

Hi , I had a same problem. And took long time around this. With above solution. It is working fine. Thanks you very much. Fahim

Contributor
Posts: 68

Re: Why SAS email attachment works for CSV file but not xlsx?

Experienced the same problem and this solved for it. Thanks!
Super User
Posts: 728

Re: Why SAS email attachment works for CSV file but not xlsx?

Because of @brulard's recent reply to this topic, it showed up on recent activity.

 

@Eusuee.  If you are still around, why not mark this topic as solved?

Post a Question
Discussion Stats
  • 10 replies
  • 5176 views
  • 6 likes
  • 7 in conversation