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

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

 

 EmailExample.JPG

 

Thanks in advance for your help!

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

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:

use_ods_text_examp.png

 

Cynthia

View solution in original post

2 REPLIES 2
Cynthia_sas
SAS Super FREQ

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:

use_ods_text_examp.png

 

Cynthia

DanielJForman
Calcite | Level 5
Thank you, Cynthia. All I needed to do was swap out my DATA _NULL_ statements for ODS TEXT = " ". It worked perfectly.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 2886 views
  • 0 likes
  • 2 in conversation