BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Timg
Fluorite | Level 6

Hello, I have some code that successfully includes table values in an email using the "Proc Print" procedure. Now I would like to add an .xls attachment in the same email. When I include the "ATTACH" code I receive an error stating the code is out of order. My email still sends although without the attachment. Suspecting I need to add more ODS statements.

 

Here is my code... Thanks!

 

FILENAME mail EMAIL TO=("xxx.com" )
FROM = "xxx.com"
SUBJECT="xxx" CONTENT_TYPE="text/html";
ODS LISTING CLOSE;
ODS HTML BODY=mail;
FILENAME PRINT;
PUT "Good Morning, Attached is .... Please let me know if you have any questions"
ATTACH = ( "xxx..xls" content_type="application/excel");
PROC PRINT DATA=Exclusion_Summ NOOBS;
RUN;
PROC PRINT DATA=Report_Summ NOOBS;
RUN;
PROC PRINT DATA=Output_Summ NOOBS;
RUN;
ODS HTML CLOSE;
ODS LISTING;
1 ACCEPTED SOLUTION

Accepted Solutions
Timg
Fluorite | Level 6

Thank you so much Chris! Works great, here is the code

FILENAME mail EMAIL TO=("xxx.com" )
FROM = "xxx.com"
SUBJECT="xxx" CONTENT_TYPE="text/html";

ATTACH = ( "/xx/xx..xls" content_type="application/excel"); ODS LISTING CLOSE; ODS HTML BODY=mail; data _null_; file MAIL; PUT "Good Morning, Attached is .... Please let me know if you have any questions"; RUN; PUT "Good Morning, Attached is .... Please let me know if you have any questions" ATTACH = ( "xxx..xls" content_type="application/excel"); PROC PRINT DATA=Exclusion_Summ NOOBS; RUN; PROC PRINT DATA=Report_Summ NOOBS; RUN; PROC PRINT DATA=Output_Summ NOOBS; RUN; ODS HTML CLOSE; ODS LISTING;

View solution in original post

2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

1. The PUT statement must be inside a data step. Add:

data _null_;
  file MAIL;

before the PUT statement.

 

2. ATTACH is an option for the FILENAME statement.

Timg
Fluorite | Level 6

Thank you so much Chris! Works great, here is the code

FILENAME mail EMAIL TO=("xxx.com" )
FROM = "xxx.com"
SUBJECT="xxx" CONTENT_TYPE="text/html";

ATTACH = ( "/xx/xx..xls" content_type="application/excel"); ODS LISTING CLOSE; ODS HTML BODY=mail; data _null_; file MAIL; PUT "Good Morning, Attached is .... Please let me know if you have any questions"; RUN; PUT "Good Morning, Attached is .... Please let me know if you have any questions" ATTACH = ( "xxx..xls" content_type="application/excel"); PROC PRINT DATA=Exclusion_Summ NOOBS; RUN; PROC PRINT DATA=Report_Summ NOOBS; RUN; PROC PRINT DATA=Output_Summ NOOBS; RUN; ODS HTML CLOSE; ODS LISTING;

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

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