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;
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;
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;
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
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;
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
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;
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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.