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;
SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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