This tutorial explains how to send emails with attachments via SAS.
Send Emails with Attachments and cc Options
If Error sending XLSX files
"Excel found unreadable content in "temp.xlsx". Do you want to recover the contents of this workbook? If you trust the source of this workbook, click yes. Excel cannot open the file "temp.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."
Solution : Use content_type option in the attach statement.
Send Emails with Attachments and cc Options
data _null_;Note : You can also add BCC option. For eg. bcc="abc@site.com"
file sendit email
from="abc@provider.com"
to=("xyz@provider.com")
cc=("uvxyz@provider.com"
"pqrs@provider.com")
subject="Important Document"
importance="High"
attach=("C:\xxxx\Proc_logistic.xls");
put "Please find attached the file";
put;
put "Thanks!";
run;
If Error sending XLSX files
"Excel found unreadable content in "temp.xlsx". Do you want to recover the contents of this workbook? If you trust the source of this workbook, click yes. Excel cannot open the file "temp.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."
Solution : Use content_type option in the attach statement.
attach=("C:\xxxx\Proc_logistic.xlsx" content_type="application/xlsx")List of Content_type options with file extensions
Extension | Content_type |
---|---|
bmp | image/bmp |
csv | application/vnd.ms-excel |
doc | application/msword |
exe | application/octet-stream |
gif | image/gif |
htm | application/html |
html | applicaton/html |
jpeg | image/jpeg |
jpg | image/jpeg |
log | text/plain |
application/pdf | |
png | image/png |
ppt | application/vnd.ms-powerpoint |
sas7bdat | application/sas |
tar | application/x-tar |
text | text/plain |
txt | text/plain |
xls | application/excel |
xlsx | application/xlsx |
zip | application/x-zip-compressed |
Send Multiple Attachments
data _null_;
file sendit email
from="abc@provider.com"
to=("xyz@provider.com")
cc=("uvxyz@provider.com"
"pqrs@provider.com")
subject="Important Document"
importance="High"
attach=("C:\Deepanshu\Proc_logistic.xlsx" content_type="application/xlsx"
"C:\Deepanshu\Summary.pdf" content_type="application/pdf"
"C:\Deepanshu\Summary.doc" content_type="application/word");
put "Please find attached the file";
put;
put "Thanks!";
put;
run;
Thanks
ReplyDeleteThanks for this!
ReplyDeleteWhat if we want to send multiple SAS datasets into one excel file but into different sheets??
ReplyDeleteYou can create XLSX file using ODS output like below.
Deleteods excel file="C:\test\test1.xlsx" ;
ods excel options(sheet_name="First Worksheet");
proc print data=sashelp.cars noobs;
run;
ods excel options(sheet_name="Second Worksheet");
proc print data=sashelp.class noobs;
run;
ods excel close;
Can we rename the attachment in attach clause?
ReplyDeleteexcellent, it helped me a lot to send the logs to client.
ReplyDeleteDo you know how can we create password protected zip file from multiple Xlsx file and send it over email?
ReplyDeleteThanks for your post. It helped me a lot when I try to send multiple XLSX files.
ReplyDeleteHow to limit the size of attached excel to 50mb ?
ReplyDelete