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;

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