Dear Sascommunity,
I am trying to create an email template with table and text. the table should be on the Top and followed by the Text.
Here is my sample output examples.
ID | ISO | NAME | ISONAME | region | pop |
182 | 050 | BANGLADESH | BANGLADESH | SEAR | 141,822,276 |
200 | 064 | BHUTAN | BHUTAN | SEAR | 2,162,546 |
250 | 104 | MYANMAR | MYANMAR | SEAR | 50,519,492 |
Demographic analysis, the statistical description of human populations, is a tool used by government agencies, political parties, and manufacturers of consumer goods. Polls conducted on every topic imaginable, from age to toothpaste preference, give the government and corporations an idea of who the public is and what it needs and wants. The government's census, which is conducted every ten years, is the largest demographic survey of all. They must qualify as economically disadvantaged either by direct certification or a supplemental household survey. Today demographic is also being used as a noun; so, for example, TV advertisers are constantly worrying about how to appeal to the 18-to-24-year-old demographic.
Thank you,
the below is my sample codes.
proc sort data=sashelp.DEMOGRAPHICS out=email;
by region id;
run;
%MACRO EMAIL(region);
FILENAME MYMAIL EMAIL
TO = "tekish20@yahoo.com"
CC = "tekish20@yahoo.com"
SUBJECT = "DEMOGRAPHICS"
CT = "TEXT/HTML"
FROM = "tekish20@yahoo.com"
SENDER = "tekish20@yahoo.com"
REPLYTO = "tekish20@yahoo.com"
content_type="text/html";
DATA TEMP;
SET email;
BY region ID;
where region="®ion";
RUN;
DATA _NULL_;
FILE MYMAIL;
SET TEMP END=EOF;
IF _N_=1 THEN DO;
%IF &TESTING = Y %THEN %DO;
temail = "tekish20@yahoo.com";
semail = "tekish20@yahoo.com";
%END;
PUT '!EM_TO! ' temail;
PUT '!EM_CC! ("' semail '")';
PUT '<html><body><font face = "Times New Roman" size = "3" color = "000000">';
PUT "Dear ";
PUT "<p>";
PUT "<P>";
PUT '<table border = 1>';
PUT '<tr>';
PUT '<td><b>ID</b></td>';
PUT '<td><b>ISO</b></td>';
PUT '<td><b>NAME</b></td>';
PUT '<td><b>ISONAME</b></td>';
PUT '<td><b>region</b></td>';
PUT '<td><b>pop</b></td>';
PUT '</tr>';
END;
PUT '<tr>';
PUT '<td>' ID '</td>';
PUT '<td>' ISO '</td>';
PUT '<td>' NAME '</td>';
PUT '<td>' ISONAME '</td>';
PUT '<td>' region '</td>';
PUT '<td>' pop '</td>';
PUT '</tr>';
IF EOF THEN DO;
PUT '</table>';
PUT '</body></html>';
END;
PUT "<p>";
PUT "<P>";
PUT "<TD>";
PUT "<P>Demographic analysis, the statistical description of human populations, is a tool used by";
PUT "government agencies, political parties, and manufacturers of consumer goods. Polls conducted ";
PUT "on every topic imaginable, from age to toothpaste preference, give the government and";
PUT "corporations an idea of who the public is and what it needs and wants. The government's";
PUT "census, which is conducted every ten years, is the largest demographic survey of all.";
PUT "They must qualify as economically disadvantaged either by direct certification or a supplemental household survey.";
PUT "Today demographic is also being used as a noun; so, for example, TV advertisers are constantly";
PUT "worrying about how to appeal to the 18-to-24-year-old demographic.";
PUT "<P>";
PUT "<p>";
PUT "<P>";
PUT "<P>";
PUT "<P>";
PUT "<P>Thank you,";
PUT "</TD>";
RUN;
FILENAME MYMAIL CLEAR;
%MEND EMAIL;
%let TESTING = Y;
proc sort data=email out=drivers(keep=region) nodupkey;
by region ;
run;
DATA _NULL_;
SET drivers;
BY region;
IF region='SEAR';
CALL EXECUTE('%EMAIL('||region||')');
RUN;
Thanks,
This works:
filename REPORT "%sysfunc(pathname(work))\test.html";
filename SEND email to = "xxx"
subject = "test"
from = "xxx"
content_type = "text/html";
ods html file=REPORT;
proc print data=SASHELP.CLASS; run;
ods html close;
data _null_;
infile REPORT;
file SEND;
input;
if _infile_ ne '</html>' then put _infile_;
else do;
put '<p>More text</p></html>';
end;
run;
This works:
filename REPORT "%sysfunc(pathname(work))\test.html";
filename SEND email to = "xxx"
subject = "test"
from = "xxx"
content_type = "text/html";
ods html file=REPORT;
proc print data=SASHELP.CLASS; run;
ods html close;
data _null_;
infile REPORT;
file SEND;
input;
if _infile_ ne '</html>' then put _infile_;
else do;
put '<p>More text</p></html>';
end;
run;
Thanks ChrisNZ .
Something like this?
data _null_;
infile REPORT;
file SEND;
input;
if _infile_ ne '</html>' then put _infile_;
else do;
infile INFO end=OEF;
do until EOF;
input ;
put _infile_;
end;
put '</html>';
end;
run;
Sorry can't test, there may be errors, but that's the gist.
If you want the text at the top, why do you write it at the bottom?
</html> is the bottom of the document (looking for </body> would be better test actually).
And <body> is the start of the page.
Do you understand the code you are running?
Not too sure what more I could supply.
If you write you text when you find <body> you'll write at the top of the html page. Something like:
if _infile_ =: '<body' then do; ***write additional header*** (see my message #5 with
infile INFO end=OEF;
)
put _infile_;
end;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.