Hi,
I want to create letters to all students using my sas dataset. Can someone help how I can do it please.
data have;
input Name $ Class $ ST_ID $ Course $ Score date;
informat date ddmmyy8.;
format date date9.;
cards;
John Grade10 101 Eng 20 01/01/82
Mary Grade11 105 Bio 25 25/11/99
Paul Grade11 105 Math 18 23/09/00
Jenny Grade11 105 Eng 15 11/12/01
;
RUN;
Here is my output letter that I want to print in pdf.
Dear Name,
Your Course Grade is Score.
You will be attending to the graduation on Date.
Thank You,
School Principal
Could be solved by using report writing interface inside ods pdf or rtf. Sorry, no time to provide code.
Hi mlogan
I think the following code might reach your requirement.
I have assumed st_id as student Id and that would be unique for each student, so I have written a conditional statement with st_id; to create letters os student specific
data have;
input Name $ Class $ ST_ID Course $ Score date;
informat date ddmmyy8.;
format date date9.;
cards;
John Grade10 101 Eng 20 01/01/82
Mary Grade11 102 Bio 25 25/11/99
Paul Grade11 103 Math 18 23/09/00
Jenny Grade11 104 Eng 15 11/12/01
;
RUN;
ods pdf file = '\path\filename.pdf';
data want(keep = letter);
set have;
if ST_ID = 101 then
letter = "Dear student"||name||
"Your"||Course||"grade is"||score||
"You will be attending to the graduation on"||put(date,date9.);
if letter ne " ";
run;
ods pdf close
Thanks and Regards,
manoj
Start by creating a test pdf document, eg like this:
%let student=John;
%let course=Eng;
%let score=20;
%let date=01/01/82;
ods pdf file='$HOME/sascommunity/letter.pdf';
ods text="Dear &student.,";
ods text="Your &course. grade is &score..";
ods text="You will be attending to the graduation on &date..";
ods text="";
ods text="Thank you,";
ods text="";
ods text="School Principal";
ods pdf close;
Then, attach the file to the email:
filename out email
attach='$HOME/sascommunity/letter.pdf'
to="&student.@school.edu"
subject='Graduation'
;
data _null_;
file out;
put 'Your graduation letter';
run;
filename out clear;
As you can see, all variable parts (text, email address) are kept in macro variables.
Once you have checked this works, wrap it into a macro:
%macro email_to_student(student,course,grade,date);
/* code from above */
%mend;
Once you've tested this with a manual macro call, use it in call execute:
data _null_;
set have;
call execute('%nrstr(%email_to_student(' !! strip(name) !! ',' !! strip(course) !! ',' !! put(score,2.) !! ',' !! put(date,ddmmyy8.) !! '));');
run;
I remembered @Cynthia_sas posted some kind of code a couple of years ago. Maybe she could post it again for you.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.