SAS insert text into email body - sas

This is the original code.
filename outmail email type='text/html'
subject='see this'
from="..."
to="..."
attach=("\...\a.pdf"content_type="application/pdf");
ods _all_ close;
ods listing close;
ods html body=outmail style=minimal;
title1 'AAA';
title2 'BBB';
proc tabulate data=
...
run;
ods html close;
ods listing;
But now I don't want to show a tabulated output in the email body, so I remove this part from the original code.
proc tabulate data=
...
run;
The problem is I won't have titles in the email any more. It seems I have to put some proc in the code to make titles exist in the email. But I don't want to show anything in the email body except
Hi all,
Regards,
Balala
Update
I tried this but no luck.
filename outmail email type='text'
subject="AAAA"
from="..."
to="..."
attach=("\\...\text.pdf" content_type="application/pdf");
data _null_;
file outmail;
put 'Hi all,';
put 'First line';
put 'Second line ';
put ' ';
put 'Regards,';
put 'Balala';
run;
But in the email, it shows Hi all,First lineSecond line Regards,Balala.
Update2
The 2nd option doesn't work for me.
1st option doesn't work at first, but when I restart SAS session, it works. But I haven't changed any setting.
And interestingly, I change the type to text/plain instead of text or text/html then everything works fine

You have two options there.
Options 1: HTML tags
Specify HTML tags in your email if you are doing content_type="text/html"
Example:
filename mailbox email 'me#example.com' subject='test email' content_type="text/html";
data _null_;
file mailbox;
put "<body>";
put "<p>Hello,</p>" ;
put "<p>Test email sent <br> Regards,</p>" /
'Automated SAS Code';
put "</body>";
RUN;
Options 2 "Backslash" pointer:
Specify backslash at the end of the line to make the pointer to go over the line. Beware of what Quentin pointed in the comments, you could end up with double lines. Depends on the your SAS platform and email server. Documented here (search for in the document "/"): http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000161869.htm
filename mailbox email 'me#example.com' subject='test email';
data _null_;
file mailbox;
put "Hello," /;
put "Test email sent. "/;
put "Regards," /;
put "Automated SAS Code";
RUN;
Regards,
Vasilij

Related

Mailing using SAS EG

I wrote some code which has to send one letter to one person with specified attachment. Here is the code:
%macro send;
%do i=1 %to &numPeople;
%let name = &&name&i;
%let to = &&UserMail&i;
options emailsys=smtp emailhost=smtp.mail.com emailport=25;
filename outbox email
to=('<Bob#mail.com>' )
type='text/html'
subject="Data for &date_today &to "
from= ('< Dataanalist#mail.com >')
sender=('< Dataanalist#mail.com >')
importance='high'
attach=("/folder/statement&i..xlsx" ct='application/excel');
ods html body=outbox style=seaside;
data _null_;
file outbox;
PUT '<html><body>';
PUT ‘Dear coleagse <br><br>';
ods html close;
run;
%end;
%mend; %send;
The problem is that now this code sends one letter just attachment (without text), the second one to the same person as I need text + attachment. How to avoid first incorrect letter?
There are two statements in your code instructing the email to 'send':
Since you set the destination of the ODS body to 'outbox', the ods html close statement will send the email.
The end of the data step (run;) will send the email.
If you remove both ODS statements (as you don't seem to be using the ODS for anything else), you should get just one email with the attachment and the text.
There's a good SAS Global Forum paper about sending emails from SAS here (PDF):
Paper 038-2008 - Sending E-mail from the DATA step - Erik W. Tilanus, consultant, Driebergen, the Netherlands

Proc Report and special character

I would like to use proc report in SAS .
My code is :
define email/display style(column)={cell width=500}
I would like display email address. In output I haven't got # sign.
Please help me.
Check what you have set as the SPLIT= character on the PROC statement.
Example:
data test;
email='user#host';
run;
proc report data=test split='#';
title1 "Split='#'";
define email / flow ;
run;
proc report data=test ;
title1 "No SPLIT= option";
define email / flow ;
run;
Listing output:
Split='#'
email
user
host
No SPLIT= option
email
user#host

Sending an email from SAS with report AND text in the body

I've created a report in SAS EG 7.2 and have got SAS to email it in the body of the email, however I can't seem to add any text. I have got this code:
filename mymail email
to=('mail#email.com')
subject='Report'
from='mail#email.com'
Content_type="text/html";
ods _all_ close;
ODS ESCAPECHAR='^';
ods html body=mymail style=minimal;
proc report data=data…
…
run;
ods html close;
ods _all_ close;
This sends my email perfectly. And I can do this to add some text
filename mymail email
to=('mail#email.com')
subject='Report'
from='mail#email.com'
Content_type="text/html";
ods _all_ close;
ODS ESCAPECHAR='^';
ods html body=mymail style=minimal;
DATA _null_;
file mymail;
Put "Hello,"//
"You are recieving this mail because:"//;
if &warn1=1 then do;
put "&w1." //; end;
if &warn2=1 then do;
put "&w2." //; end;
put
"Regards,"//
"Chris";
run;
ods html close;
ods _all_ close;
But I can't seem to do both? If I include the text step and the proc report, I only see the report in the resulting email. Any ideas?
Thanks in advance :)
If anyone is interested I managed to solve this by adding in the following line directly before the proc report:
ods html text="<div>Please find below the Reports </div> <br><br> There are &&totalwarnings. warnings for the last hour:<br><br>";
%if &warn1=1 %then %do;
ods html text="&&w1."; %end;
%if &warn2=1 %then %do;
ods html text="&&w2."; %end;
Your solution of adding the text into the HTML file itself sounds best.
Your original code has a couple of issue.
First you have an access conflict. The DATA _NULL_ step is trying to write to the same file that the ODS HTML process is still writing to. Didn't you get an error message? or perhaps two separate emails?
Second even if you succeeded in writing text into the same file as the ODS HTML was producing it would be either before or after the <HTML>..</HTML> tags around the report generated by ODS HTML. As such it would probably be ignored by the recipient.

The date and the time that SAS program started are printed at the top of each page in listing output, why are not printed on html output?

options date/nodate;
This option has no effect on my html output but it works fine on listing output. Also explain how to print date time on html output same like listing output?
/*----prints date in the upper right side of the output------*/
options dtreset date;
ods listing;
Title; /*I dont want to print any title*/
proc print data=sashelp.class;
run;
ods listing close;
/*----for html ods, date is not printed----------------------*/
options dtreset date;
ods html;
Title; /*I dont want to print any title*/
proc print data=sashelp.class;
run;
ods html close;
Working as designed; according to the documentation:
Note: In an interactive SAS session, the date and time are noted only in the output window.
Output window means the listing destination, by the way (separate from the Results Window which is where modern ODS destinations, including HTML, go).
If you want it in HTML, you'll need to add it to the title:
title "(other things) &sysdate.";
Or &Sysdate9. if you prefer that format.
Some other ways to do this are discussed in Art Carpenter's Placing Dates in Your Titles.

Print superscript or subscript in SAS without ODS

This can be achieved using ODS, but I have a constraint that I am not supposed to use ODS as I'm using Listing. I need to generate RTF reports which has super and subscript text in them. Below is the sample code which I was referring which uses ODS.
ods rtf file='temp.rtf';
ods escapechar='^';
proc print data=sashelp.class;
title 'this value is superscripted ^{super 2} ';
title2 'this value is subscripted ^{sub 2} ';
run;
ods rtf close;
I want to print superscript or subscript text in Proc report title or footnotes.
Silly constraint calls for equally silly solution - who needs ODS escapechar when you can hard-code the rtf control sequences for subscripts and superscripts?
x 'cd c:\temp';
/*Produce initial rtf without superscripts / subscripts*/
ods rtf file='temp.rtf';
proc print data=sashelp.class;
title 'this value is superscripted 2';
title2 'this value is subscripted 2';
run;
ods rtf close;
/*Add them in manually as per .rtf file format specification*/
data _null_;
infile "c:\temp\temp.rtf" lrecl = 32767;
file "c:\temp\want.rtf";
input;
length rtf $32767;
rtf = _infile_;
rtf = tranwrd(rtf, 'this value is superscripted 2', 'this value is superscripted \super 2 \nosupersub');
rtf = tranwrd(rtf, 'this value is subscripted 2', 'this value is subscripted \sub 2 \nosupersub');
put rtf;
run;
I don't believe this is possible in ODS LISTING. (Anyone who tells you you aren't using ODS is wrong, because listing is an ODS output destination just like all of the other destinations, but i'm assuming you mean you can't use anything other than ODS Listing, or use some of the common ODS tricks like ODS ESCAPECHAR).
However, ODS Listing doesn't have much available to it in terms of playing with fonts. You can put a super-2:
ods listing;
proc print data=sashelp.class;
title "Fun²";
run;
ods listing close;
by literally typing the character into your text, but that's not available for every possible superscript, and I don't think there are subscript equivalents in the listing font.
You can find a listing of characters online, for example in this paper. You can insert them with '##'x where ## is the 2 digit hex code for the character, or by typing them (alt+0178 for ² for example, or use character map to find them; make sure you use the right font.)