Greetings from Minnesota;
I am sending an email via SAS code, and I am having some trouble with some of the formatting.
I successfully figured out how to put text, then a report, and then more text into the email; moreover, I added a PROC FORMAT to modify a STYLE to remove borders and unnecessary style effects from my text. However, there are large gaps (spacings, margins, etc. - I'm not sure of the proper term) before and after my "opening" and "closing" texts. Is there a way to collapse these large spaces to produce a much shorter email body?
My Code
PROC TEMPLATE;
DEFINE STYLE STYLES.SASWEBMOD;
PARENT=STYLES.SASWEB;
CLASS SYSTITLEANDFOOTERCONTAINER / HTMLSTYLE="BORDER:NONE";
END;
RUN;
FILENAME MYMAIL EMAIL
FROM = "JOHN_DOE@COMPANY.COM"
TO = "JOHN_DOE@COMPANY.COM"
SUBJECT = "TEST EMAIL SUBJECT"
CONTENT_TYPE = "TEXT/HTML";
ODS _ALL_ CLOSE;
ODS HTML3 BODY=MYMAIL RS=NONE STYLE=SASWEBMOD;
OPTIONS NOCENTER;
/*OPENING TEXT*/
DATA _NULL_;
FILE PRINT;
PUT "The text that precedes the SAS Report goes here.";
RUN;
/*REPORT*/
TITLE1 "SAS Report header goes here.";
PROC REPORT DATA = SASHELP.CLASS(OBS=5);
COLUMNS _ALL_;
DEFINE _ALL_ / DISPLAY CENTER;
RUN;
TITLE;
/*CLOSING TEXT*/
DATA _NULL_;
FILE PRINT;
PUT "The text that proceeds the SAS Report goes here.";
RUN;
ODS _ALL_ CLOSE;
ODS LISTING;
Sample Output
Thanks in advance for your help!
Hi:
I typically send email as an attachment because many companies don't allow email with HTML in the body of the mail or they convert the HTML to plain text before delivery. With an attachment of the report as a PDF or RTF file, I am more sure that the mail will go through the system unchanged.
I see that you're using ODS HTML3 -- that is older HTML destination. You're getting a logical PAGE break (that horizontal rule is an HTML indicator of a page break) between each of your outputs because of the DATA _NULL_ steps. Have you considered using ODS TEXT=. I did not send an email, but I created output with the following code (using your same template):
ODS _ALL_ CLOSE;
ODS PDF BODY="c:\temp" FILE="usetext_acro.pdf" STYLE=SASWEBMOD startpage=no;
ODS HTML4 BODY="c:\temp" FILE="usetext_ht4.html" RS=NONE STYLE=SASWEBMOD;
ODS HTML3 BODY="c:\temp" FILE="usetext_ht3.html" RS=NONE STYLE=SASWEBMOD;
OPTIONS NOCENTER;
/*OPENING TEXT*/
ods text="The text that precedes the SAS Report goes here.";
/*REPORT*/
TITLE1 "SAS Report header goes here.";
PROC REPORT DATA = SASHELP.CLASS(OBS=5);
COLUMNS _ALL_;
DEFINE _ALL_ / DISPLAY CENTER;
RUN;
TITLE;
/*CLOSING TEXT*/
ods text="The text that follows the SAS Report goes here.";
ODS _ALL_ CLOSE;
ODS LISTING;
and got these results in the HTML3 output file:
Cynthia
Hi:
I typically send email as an attachment because many companies don't allow email with HTML in the body of the mail or they convert the HTML to plain text before delivery. With an attachment of the report as a PDF or RTF file, I am more sure that the mail will go through the system unchanged.
I see that you're using ODS HTML3 -- that is older HTML destination. You're getting a logical PAGE break (that horizontal rule is an HTML indicator of a page break) between each of your outputs because of the DATA _NULL_ steps. Have you considered using ODS TEXT=. I did not send an email, but I created output with the following code (using your same template):
ODS _ALL_ CLOSE;
ODS PDF BODY="c:\temp" FILE="usetext_acro.pdf" STYLE=SASWEBMOD startpage=no;
ODS HTML4 BODY="c:\temp" FILE="usetext_ht4.html" RS=NONE STYLE=SASWEBMOD;
ODS HTML3 BODY="c:\temp" FILE="usetext_ht3.html" RS=NONE STYLE=SASWEBMOD;
OPTIONS NOCENTER;
/*OPENING TEXT*/
ods text="The text that precedes the SAS Report goes here.";
/*REPORT*/
TITLE1 "SAS Report header goes here.";
PROC REPORT DATA = SASHELP.CLASS(OBS=5);
COLUMNS _ALL_;
DEFINE _ALL_ / DISPLAY CENTER;
RUN;
TITLE;
/*CLOSING TEXT*/
ods text="The text that follows the SAS Report goes here.";
ODS _ALL_ CLOSE;
ODS LISTING;
and got these results in the HTML3 output file:
Cynthia
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.