Dear experts,
I want to create an automated email with different table inside the order list.
here is the sample output.
Subject: list of variable from Sashelp
Dear [ Name]:
Name | Sex | age | Height | Weight |
Joyce | F | 11 | 51.3 | 50.5 |
Thomas | M | 11 | 57.5 | 85 |
3.List of student below with age eleven.
Name | Sex | age | Height | Weight |
Joyce | F | 11 | 51.3 | 50.5 |
Thomas | M | 11 | 57.5 | 85 |
Thank you for you for helping .
here is the sample SAS codes.
data class;
set sashelp.class;
run;
PROC SORT DATA=CLASS;
BY AGE;
RUN;
%MACRO test(FLD,RECIPIENT_EMAIL,RECIPIENT_NAME,LEVEL);
FILENAME MYMAIL EMAIL
TO = "emailadderess@test1.com"
FROM = "emailadderess@test1.com"
SENDER = "emailadderess@test1.com"
REPLYTO = "emailadderess@test1.com"
BCC = "emailadderess@test1.com"
CT = "TEXT/HTML";
DATA TEMP;
SET class;
BY age;
IF (&FLD = "&LEVEL");
RUN;
DATA _NULL_;
FILE MYMAIL;
SET TEMP END = EOF;
IF _N_ = 1 THEN DO;
%LET RECIPIENT_NAME=Name of the person;
/*TO = "&RECIPIENT_EMAIL";*/
TO = "emailadderess@test1.com";
PUT '!EM_TO! ' TO;
PUT '!EM_SUBJ! ' "list of variable from Sashelp &LEVEL";
PUT '<html><body><font face = "Cambria" size = "3" color = "000000">';
PUT "Dear &RECIPIENT_NAME;";
PUT '<p>';
PUT "<p>";
PUT "<p>";
PUT "<ol><li>Select <b>Name of student from sashelp</b></li>";
PUT "<li>list of student below with age 11 </b> section. </li>";
PUT '<p>';
PUT '<p>';
PUT '<p>';
PUT '<p>';
PUT '<table border = 1>';
PUT '<tr>';
PUT '<td><b>Name</b></td>';
PUT '<td><b>sex</b></td>';
PUT '<td><b>age</b></td>';
PUT '<td><b>height</b></td>';
PUT '<td><b>weight</b></td>';
PUT '</tr>';
END;
PUT '<tr>';
PUT '<td>' Name '</td>';
IF sex=M THEN
PUT '<td> <font color=#FF6342><b>' sex '</font></b></td>';
ELSE PUT '<td>' sex '</td>';
IF age=14 THEN
PUT '<td> <font color=#FF6342><b>' age '</font></b></td>';
ELSE PUT '<td>' age '</td>';
IF height>10 THEN
PUT '<td> <font color=#FF6342><b>' height '</font></b></td>';
ELSE PUT '<td>' height '</td>';
IF weight<30 THEN
PUT '<td> <font color=#FF6342><b>' weight '</font></b></td>';
ELSE PUT '<td>' weight '</td>';
PUT '</ol>';
PUT '</tr>';
IF EOF THEN DO;
PUT '</table>';
PUT '</body></html>';
END;
PUT "<li>list of student above with age 11 </b></li>";
PUT '</ol>';
PUT '</tr>';
PUT '<table border = 1>';
PUT '<tr>';
PUT '<td><b>Name</b></td>';
PUT '<td><b>sex</b></td>';
PUT '<td><b>age</b></td>';
PUT '<td><b>height</b></td>';
PUT '<td><b>weight</b></td>';
PUT '</tr>';
END;
PUT '<tr>';
PUT '<td>' Name '</td>';
IF sex=M THEN
PUT '<td> <font color=#FF6342><b>' sex '</font></b></td>';
ELSE PUT '<td>' sex '</td>';
IF age=14 THEN
PUT '<td> <font color=#FF6342><b>' age '</font></b></td>';
ELSE PUT '<td>' age '</td>';
IF height>10 THEN
PUT '<td> <font color=#FF6342><b>' height '</font></b></td>';
ELSE PUT '<td>' height '</td>';
IF weight<30 THEN
PUT '<td> <font color=#FF6342><b>' weight '</font></b></td>';
ELSE PUT '<td>' weight '</td>';
PUT '</ol>';
PUT '</tr>';
IF EOF THEN DO;
PUT '</table>';
PUT '</body></html>';
END;
RUN;
FILENAME MYMAIL CLEAR;
%MEND test;
PROC SORT DATA=class OUT=DRIVER_AGE(KEEP=age) NODUPKEY;
BY age;
RUN;
DATA _NULL_;
SET DRIVER_AGE;
BY age;
IF age=11;
CALL EXECUTE('%test(AGE,'||RECIPIENT_EMAIL||','||RECIPIENT_NAME||','||AGE||')');
RUN;
In your point of view, Do you want to create a mail list to each student. Is it correct?
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.