<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Inserting data into letter in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Inserting-data-into-letter/m-p/474422#M121903</link>
    <description>&lt;P&gt;I remembered&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13549"&gt;@Cynthia_sas&lt;/a&gt;&amp;nbsp;posted some kind of code a couple of years ago. Maybe she could post it again for you.&lt;/P&gt;</description>
    <pubDate>Fri, 29 Jun 2018 13:16:29 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2018-06-29T13:16:29Z</dc:date>
    <item>
      <title>Inserting data into letter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Inserting-data-into-letter/m-p/474330#M121853</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I want to create letters to all students using my sas dataset. Can someone help how I can do it please.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is my output letter that I want to print in pdf.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dear &lt;STRONG&gt;Name&lt;/STRONG&gt;,&lt;BR /&gt;Your &lt;STRONG&gt;Course&lt;/STRONG&gt; Grade is &lt;STRONG&gt;Score&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;You will be attending to the graduation on &lt;STRONG&gt;Date&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank You,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;School Principal&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jun 2018 02:33:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Inserting-data-into-letter/m-p/474330#M121853</guid>
      <dc:creator>mlogan</dc:creator>
      <dc:date>2018-06-29T02:33:40Z</dc:date>
    </item>
    <item>
      <title>Re: Inserting data into letter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Inserting-data-into-letter/m-p/474350#M121870</link>
      <description>&lt;P&gt;Could be solved by using report writing interface inside ods pdf or rtf. Sorry, no time to provide code.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jun 2018 06:17:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Inserting-data-into-letter/m-p/474350#M121870</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2018-06-29T06:17:40Z</dc:date>
    </item>
    <item>
      <title>Re: Inserting data into letter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Inserting-data-into-letter/m-p/474352#M121871</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35631" target="_self"&gt;&lt;SPAN class="login-bold"&gt;mlogan&lt;/SPAN&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think the following&amp;nbsp;code might reach your requirement.&lt;/P&gt;&lt;P&gt;I have assumed st_id as student Id and that would be unique for each student, so I have written a conditional statement with&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;st_id;&amp;nbsp;&lt;/STRONG&gt;to create letters os student&amp;nbsp;specific&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;&lt;BR /&gt;ods pdf close&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;Thanks and Regards,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;manoj&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jun 2018 06:42:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Inserting-data-into-letter/m-p/474352#M121871</guid>
      <dc:creator>s_manoj</dc:creator>
      <dc:date>2018-06-29T06:42:00Z</dc:date>
    </item>
    <item>
      <title>Re: Inserting data into letter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Inserting-data-into-letter/m-p/474358#M121876</link>
      <description>&lt;P&gt;Start by creating a test pdf document, eg like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let student=John;
%let course=Eng;
%let score=20;
%let date=01/01/82;

ods pdf file='$HOME/sascommunity/letter.pdf';

ods text="Dear &amp;amp;student.,";
ods text="Your &amp;amp;course. grade is &amp;amp;score..";
ods text="You will be attending to the graduation on &amp;amp;date..";
ods text="";
ods text="Thank you,";
ods text="";
ods text="School Principal";

ods pdf close;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then, attach the file to the email:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename out email
  attach='$HOME/sascommunity/letter.pdf'
  to="&amp;amp;student.@school.edu"
  subject='Graduation'
;

data _null_;
file out;
put 'Your graduation letter';
run;

filename out clear;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As you can see, all variable parts (text, email address) are kept in macro variables.&lt;/P&gt;
&lt;P&gt;Once you have checked this works, wrap it into a macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro email_to_student(student,course,grade,date);

/* code from above */

%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Once you've tested this with a manual macro call, use it in call execute:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set have;
call execute('%nrstr(%email_to_student(' !! strip(name) !! ',' !! strip(course) !! ',' !! put(score,2.) !! ',' !! put(date,ddmmyy8.) !! '));');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Jun 2018 07:09:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Inserting-data-into-letter/m-p/474358#M121876</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-06-29T07:09:30Z</dc:date>
    </item>
    <item>
      <title>Re: Inserting data into letter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Inserting-data-into-letter/m-p/474422#M121903</link>
      <description>&lt;P&gt;I remembered&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13549"&gt;@Cynthia_sas&lt;/a&gt;&amp;nbsp;posted some kind of code a couple of years ago. Maybe she could post it again for you.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jun 2018 13:16:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Inserting-data-into-letter/m-p/474422#M121903</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-06-29T13:16:29Z</dc:date>
    </item>
    <item>
      <title>Re: Inserting data into letter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Inserting-data-into-letter/m-p/474590#M121954</link>
      <description>Hi:&lt;BR /&gt;  I think you mean this previous posting:&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/ODS-and-Base-Reporting/Mail-merge-randomization-forms/td-p/172172" target="_blank"&gt;https://communities.sas.com/t5/ODS-and-Base-Reporting/Mail-merge-randomization-forms/td-p/172172&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Cynthia</description>
      <pubDate>Fri, 29 Jun 2018 20:57:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Inserting-data-into-letter/m-p/474590#M121954</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2018-06-29T20:57:20Z</dc:date>
    </item>
  </channel>
</rss>

