BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
tekish
Quartz | Level 8
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,

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

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

6 REPLIES 6
ChrisNZ
Tourmaline | Level 20

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;
ChrisNZ
Tourmaline | Level 20

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.

 

ChrisNZ
Tourmaline | Level 20

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?

 

 

 

 

 

ChrisNZ
Tourmaline | Level 20
The program modifies a HTML file to add more text. These files' structure is very simple. Look up the structure and you'll see what the issue is. You are adding text at the end of the file, so of course that text appears at the end.
ChrisNZ
Tourmaline | Level 20

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-2024.png

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.

 

Register now!

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
  • 6 replies
  • 15855 views
  • 0 likes
  • 2 in conversation