BookmarkSubscribeRSS Feed
SASGeek
Obsidian | Level 7

Hello all,

My client wants emails sent with one report in the body of the email and attached Excel files. The files, because they are large, are just straight.


proc export data=details outfile="&details" dbms=xlsx replace; sheet="Details Part1";  

 

The report they want embedded in the same report is a straight result from another dataset.

 

I can figure out how to attach or print within the email but not both. Any examples you can point me to?

 

Thank you

1 REPLY 1
ChrisHemedinger
Community Manager

This article is a good reference: How to send email using SAS 

 

You will combine two of the techniques: add an attachment and include ODS output in the body of the email. Here's a simple example:

 

options emailsys=smtp
 emailhost='yourmail.host.com';

%let outfile=c:\Projects\class.xlsx;
proc export
 data=sashelp.class
 file="&outfile"
 dbms=xlsx
 replace;
sheet="Class Roster";
run;

%let toList="recipient@destination.com";

FILENAME OUTPUT EMAIL
	SUBJECT = "Impressive Report"
	FROM = "Chris <chris.blogger@sas.com>"
	TO = (&toList)
	CT ='text/html'
  attach=("&outfile." 
  content_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");

ods tagsets.msoffice2k(id=email)
  file=OUTPUT(title="My report")
  style=htmlencore;

  /* The report body in the email */
title "Class Roster";
proc print data=sashelp.class;
run;

ods tagsets.msoffice2k(id=email) close;
Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 222 views
  • 0 likes
  • 2 in conversation