1

I have exported sas-dataset, copied to my computer using WinSCP and opened it succesfully.

However, when I sent the file using data step, the file is corrupted. I click the file in Outlook and Excel says "The workbook cannot be opened or repaired by Microsoft Excel because it it sorrupt".

What can I do to make the file openable using data step e-mail.

My code:

/* Create data */
data A;
  input B;
  datalines;
1   
  ;
run;

/* Export */
proc export 
  data=A 
  dbms=xlsx replace 
  outfile="/home/USERNAME/xlsx_export";
run;

FILENAME Mailbox EMAIL 'user.name@abc.de'
Subject='xlsx_test'
attach="/home/USERNAME/xlsx_export.xlsx";
DATA _NULL_;
  FILE Mailbox;
  PUT "xlsx test";
RUN;    
andrey_sz
  • 751
  • 1
  • 13
  • 29
  • I haven't done this in a long time, but in the past had to run binary files through UUENCODE before attaching to email. – Tom Apr 14 '16 at 20:27

1 Answers1

0

The problem is with the email - see https://communities.sas.com/t5/ODS-and-Base-Reporting/Why-SAS-email-attachment-works-for-CSV-file-but-not-xlsx/td-p/198538 which identifies this problem and solves it by changing the attach to add content_type="application/xlsx".
Try attach="/home/USERNAME/xlsx_export.xlsx" content_type="application/xlsx";

Jeff
  • 12,555
  • 5
  • 33
  • 60