DATA Step, Macro, Functions and more

how to create an automated email with table and text contents.

Accepted Solution Solved
Reply
Contributor
Posts: 53
Accepted Solution

how to create an automated email with table and text contents.

Spoiler
 

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="&region";

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,

 


Accepted Solutions
Solution
‎12-20-2016 10:02 AM
PROC Star
Posts: 1,760

Re: how to create an automated email with table and text contents.

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;

View solution in original post


All Replies
Solution
‎12-20-2016 10:02 AM
PROC Star
Posts: 1,760

Re: how to create an automated email with table and text contents.

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;
Contributor
Posts: 53

Re: how to create an automated email with table and text contents.

Thanks  .

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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