BookmarkSubscribeRSS Feed
ColeG
Obsidian | Level 7

My company has recently switched to SAS Enterprise Guide and I am updating all my codes. One thing that I need to do is send out large batches of emails with attachments.

 

I know that to include .xlsx files you need to add the line

content_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" lrecl=32000

 to your attach= statement.

 

My question is, how do you send multiple attachments, of the same or different types, in one email? I have verified that each attachment works individually (I have six total attachments to send), but only the last one attached can be opened.

 

Thanks!

 

%macro emaildata (to_address, attachments);
 Filename output email;
 data _null_;
	file output
	to = (&to_address.)
	subject = "subject"
	attach = (&attachments. content_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" lrecl=32000);

 put "text."; 

run;
%mend emaildata;

%emaildata (recipient, "&attachment1." "&attachment2." "&attachment3." "&attachment4." "&attachment5." "&attachment6.");
1 REPLY 1
tomrvincent
Rhodochrosite | Level 12

This works for me:

 

	/* email files */
	filename outbox email 'ron@acme.com';

	data _null_;
		file outbox

		/* Overrides value in filename statement */
		to=("&EMAILADDRESS" )
		subject="reports "
		
		attach=
		(
		"&outputpath./&pdbym._results.csv"
		"&outputpath./&pdbym._detail.csv"
		"&outputpath./177_&pdbmy.-&pdemy..html"
		"&outputpath./177_&pdbmy.-&pdemy..pdf"
		"&outputpath./177_&pdbmy.-&pdemy..xlsx"	content_type="application/xlsx" lrecl=32000 	
		"&outputpath./Claims_&pdbmy.-&pdemy..pdf" 
		"&outputpath./Claims_&pdbmy.-&pdemy..html" 
		"&outputpath./Claims_&pdbmy.-&pdemy..rtf"
		"&outputpath./Lines_&pdbmy.-&pdemy..pdf" 
		"&outputpath./Lines_&pdbmy.-&pdemy..html" 
		"&outputpath./Lines_&pdbmy.-&pdemy..rtf"
		"&outputpath./claims30.xlsx" content_type="application/xlsx" lrecl=32000 
		"&outputpath./interest.xlsx" content_type="application/xlsx" lrecl=32000
		"&outputpath./badclaims1.xlsx" content_type="application/xlsx" lrecl=32000
		"&outputpath./badclaims2.xlsx" content_type="application/xlsx" lrecl=32000
		"&outputpath./Detail_File.xlsx" content_type="application/xlsx" lrecl=32000
		)
		;
		
		put "Enjoy these exciting  reports .";
	run;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 4426 views
  • 1 like
  • 2 in conversation