BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Ronein
Meteorite | Level 14

Hello

I am sending email via sas program and I have some modifications that I want to do:

Issue 1:

I want to add some text in the body of email.

I added data _null_ statement but I don't see the text in the body of email.

Issue 2:

I want that the text in body will be displayed on left side of email

Issue 3:

I want that the tables in body of email will be displayed on left side of email

 


/****Send Report via email***********/
/****Send Report via email***********/
/****Send Report via email***********/
options 
emailsys=smtp 
emailhost=smtp.leumi
emailport=25;

FILENAME mail EMAIL 
TO="<Joe@gmail.com>"
FROM='<Joe@gmail.com>'
SUBJECT="XXXX" 
CONTENT_TYPE="text/html" 
encoding="utf-8";
ODS LISTING CLOSE;
ODS HTML BODY=mail;

data _null_;
put 'Hello,';
put "Please find report";
put '  ';
put '  ';
put '  ';
put 'Kind Regards,';
run;

Title 'Cars';
proc report data = SasHelp.Cars(obs = 5) split = "*";
column Type MPG_Ratio MPG_City MPG_Highway;
define Type / display ;
define MPG_City / display;
define MPG_Highway / display;
define MPG_Ratio / computed 'City/Highway' format = 4.2;
compute MPG_Highway;  
MPG_Ratio = MPG_City/MPG_Highway;
endcomp;
run;

Title 'class';
proc report data = SasHelp.class(obs = 5);
run;

ODS HTML CLOSE;
ODS LISTING;

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

The content from your DATA _null_ step is not added to the file that you are targeting for email. Since you want the content to be HTML, consider using PROC ODSTEXT instead -- inside of the ODS HTML block --  to capture the text you want to add above your report. Check the documentation for style/formatting options and examples.

 

 

proc odstext;
 heading 'MY Report!';
 p 'Hello, please find my report below.';
run;

Title 'Cars';
proc report data = SasHelp.Cars(obs = 5) split = "*";
column Type MPG_Ratio MPG_City MPG_Highway;
define Type / display ;
define MPG_City / display;
define MPG_Highway / display;
define MPG_Ratio / computed 'City/Highway' format = 4.2;
compute MPG_Highway;  
MPG_Ratio = MPG_City/MPG_Highway;
endcomp;
run;

Title 'class';
proc report data = SasHelp.class(obs = 5);
run;

 

 

SAS Hackathon registration is open! Build your skills. Make connections. Enjoy creative freedom. Maybe change the world.

View solution in original post

5 REPLIES 5
SASJedi
SAS Super FREQ

For issue 1, your DATA _NULL_ step is writing to the SAS Log, not to ODS. For Issues 2 and 3, try setting the NOCENTER system option. Something like this should work:

/****Send Report via email***********/
/****Send Report via email***********/
/****Send Report via email***********/
options 
   nocenter
   emailsys=smtp 
   emailhost=smtp.leumi
   emailport=25
;

FILENAME mail EMAIL 
TO="<Joe@gmail.com>"
FROM='<Joe@gmail.com>'
SUBJECT="XXXX" 
CONTENT_TYPE="text/html" 
encoding="utf-8";
ODS LISTING CLOSE;
ODS HTML BODY=mail;

data _null_;
   file print;
   put 'Hello,';
   put "Please find report";
   put '  ';
   put '  ';  
   put '  ';
   put 'Kind Regards,';
run;

Title 'Cars';
proc report data = SasHelp.Cars(obs = 5) split = "*";
   column Type MPG_Ratio MPG_City MPG_Highway;
   define Type / display ;
   define MPG_City / display;
   define MPG_Highway / display;
   define MPG_Ratio / computed 'City/Highway' format = 4.2;
   compute MPG_Highway;   
      MPG_Ratio = MPG_City/MPG_Highway;
   endcomp;
run;

Title 'class';
proc report data = SasHelp.class(obs = 5);
run;

ODS HTML CLOSE;
ODS LISTING;
Check out my Jedi SAS Tricks for SAS Users
Ronein
Meteorite | Level 14

Thanks,

As I see you made 2 modifications to my code:

1- You added  " file print;"   statement  to  "data _null_;"  statement.

Can you explain what did it do? change the print on Log to email?

2-You added "nocenter"  to "Options".

 

Please see the email that was sent:

Some of the text is not on Left side

Also the titles are in boxes and I dont want boxes.

Also there are some empty boxes and I dont want it

Ronein_0-1672726272764.png

 

 

ChrisHemedinger
Community Manager

The content from your DATA _null_ step is not added to the file that you are targeting for email. Since you want the content to be HTML, consider using PROC ODSTEXT instead -- inside of the ODS HTML block --  to capture the text you want to add above your report. Check the documentation for style/formatting options and examples.

 

 

proc odstext;
 heading 'MY Report!';
 p 'Hello, please find my report below.';
run;

Title 'Cars';
proc report data = SasHelp.Cars(obs = 5) split = "*";
column Type MPG_Ratio MPG_City MPG_Highway;
define Type / display ;
define MPG_City / display;
define MPG_Highway / display;
define MPG_Ratio / computed 'City/Highway' format = 4.2;
compute MPG_Highway;  
MPG_Ratio = MPG_City/MPG_Highway;
endcomp;
run;

Title 'class';
proc report data = SasHelp.class(obs = 5);
run;

 

 

SAS Hackathon registration is open! Build your skills. Make connections. Enjoy creative freedom. Maybe change the world.
Ronein
Meteorite | Level 14

Thanks,

The text in email body is located in left side as I wanted.

Also the two summary reports are displayed in left side as I wanted.

However,

There are some empty boxed that I want to remove

Also in start of email it is written "class"  and I don't know how to remove it and why it came there

Please see the email that was sent

Ronein_0-1672727195865.png


options 
   nocenter
   emailsys=smtp 
   emailhost=smtp.leumi
   emailport=25
;
FILENAME mail EMAIL 
TO="Dave@gmail.com"
FROM='Dave@gmail.com'
SUBJECT="www" 
CONTENT_TYPE="text/html" 
encoding="utf-8";
ODS LISTING CLOSE;
ODS HTML BODY=mail;
 proc odstext;
 heading 'My Report' /Style=Header {fontsize=16pt  color=blue  fontstyle=italic};
 p 'Hello, please find my report below.';
 p '';
 p '';
 p '';
 p '';
 p 'Kind Regards,';
 p 'Dave';
run;
title;
Title 'Cars';
proc report data = SasHelp.Cars(obs = 5) split = "*";
   column Type MPG_Ratio MPG_City MPG_Highway;
   define Type / display ;
   define MPG_City / display;
   define MPG_Highway / display;
   define MPG_Ratio / computed 'City/Highway' format = 4.2;
   compute MPG_Highway;   
      MPG_Ratio = MPG_City/MPG_Highway;
   endcomp;
run;
title;
Title 'class';
proc report data = SasHelp.class(obs = 5);
run;
ODS HTML CLOSE;
ODS LISTING;

 

 

 

 

 

ChrisHemedinger
Community Manager

SAS remembers your TITLE setting unless you clear it between runs, so end your program with an empty TITLE; statement to clear the "Class" title.

 

Regarding the boxes, that's part of the ODS style. You can experiment with different styles and tagsets, or use PROC TEMPLATE to adjust. Example:

ods path(prepend) work.template(update);
proc template;
	define style styles.myemail;
		parent=styles.seaside;
			class body /	
				htmlstyle="border:none";
		        class systitleandfootercontainer /
            	                htmlstyle="border:none";
			class page /
				htmlstyle="border:none";
	end;
run;

 Then use this in your ODS HTML:

ODS HTML BODY=email style=myemail;
SAS Hackathon registration is open! Build your skills. Make connections. Enjoy creative freedom. Maybe change the world.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 2277 views
  • 7 likes
  • 3 in conversation