<?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: Email Macro-Issue in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Email-Macro-Issue/m-p/197239#M36987</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Look at where you are setting &amp;amp;cnt.&lt;/P&gt;&lt;P&gt;Since that variable controls the number of iterations that would be a very likely place for an off by one error.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 01 Jun 2015 15:52:00 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2015-06-01T15:52:00Z</dc:date>
    <item>
      <title>Email Macro-Issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Email-Macro-Issue/m-p/197233#M36981</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am having the following code. I am getting one less observation in the resulting emails. Eg. if cnt is 6, I am sending out 5 emails as result. Can anyone please let me know why this is happening and how to resolve the issue.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro mail ;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;%do i=1 %to &amp;amp;cnt.;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;data _null_;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;set ds1;&lt;/P&gt;&lt;P&gt;by name&lt;/P&gt;&lt;P&gt;if _n_=&amp;amp;i.;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;call symput('firstname',trim(NAME));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;call symput('createdemail',%str("'"||trim(EMAIL)||"'"));&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;filename MailBox&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; EMAIL &lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;A class="jive-link-email-small" href="mailto:testmail@test.com"&gt;testmail@test.com&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; TO&amp;nbsp;&amp;nbsp;&amp;nbsp; = &lt;/SPAN&gt;&lt;A class="jive-link-email-small" href="mailto:recepient@gmail.com"&gt;recepient@gmail.com&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt; SUBJECT = "Test Subject"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;data _null_;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; file MailBox;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; put "Hello &amp;amp;name." ;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;%mend mail;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;%mail;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Jun 2015 14:49:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Email-Macro-Issue/m-p/197233#M36981</guid>
      <dc:creator>sasmaverick</dc:creator>
      <dc:date>2015-06-01T14:49:27Z</dc:date>
    </item>
    <item>
      <title>Re: Email Macro-Issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Email-Macro-Issue/m-p/197234#M36982</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Well your missing a mend in there for the do loop, semicolon after filename etc..&amp;nbsp; How many records in ds1?&amp;nbsp; Can I suggest this:&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set ds1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call execute('filename MailBox email from&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;= &lt;/SPAN&gt;&lt;A class="jive-link-email-small" href="mailto:testmail@test.com" style="font-weight: inherit; font-style: inherit; font-family: inherit; color: #0e66ba;"&gt;testmail@test.com&lt;/A&gt; to&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;= &lt;/SPAN&gt;&lt;A class="jive-link-email-small" href="mailto:recepient@gmail.com" style="font-weight: inherit; font-style: inherit; font-family: inherit; color: #0e66ba;"&gt;recepient@gmail.com&lt;/A&gt; subject&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;="Test Subject";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data _null_; file mailbox; put "Hello '||strip(name)||'"; run;');&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;run;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Jun 2015 15:07:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Email-Macro-Issue/m-p/197234#M36982</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-06-01T15:07:53Z</dc:date>
    </item>
    <item>
      <title>Re: Email Macro-Issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Email-Macro-Issue/m-p/197235#M36983</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I just posted a partial piece of the code. The macro is executing, but I am getting one less than the count. That is if &amp;amp;cnt=5, I am getting only 4 emails.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Jun 2015 15:10:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Email-Macro-Issue/m-p/197235#M36983</guid>
      <dc:creator>sasmaverick</dc:creator>
      <dc:date>2015-06-01T15:10:54Z</dc:date>
    </item>
    <item>
      <title>Re: Email Macro-Issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Email-Macro-Issue/m-p/197236#M36984</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Unfortunately your not giving enough information to go on.&amp;nbsp; How many records are in the dataset ds1, remember that will define how many bits of code are generated:&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;data _null_;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;set ds1;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;by name&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;if _n_=1;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;call symput('firstname',trim(NAME));&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;call symput('createdemail',%str("'"||trim(EMAIL)||"'"));&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;data _null_;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;set ds1;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;by name&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;if _n_=2;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;call symput('firstname',trim(NAME));&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;call symput('createdemail',%str("'"||trim(EMAIL)||"'"));&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;Now in the above if ds1 only has 1 record then the second code will not do anything as _n_ != 2;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Jun 2015 15:19:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Email-Macro-Issue/m-p/197236#M36984</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-06-01T15:19:29Z</dc:date>
    </item>
    <item>
      <title>Re: Email Macro-Issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Email-Macro-Issue/m-p/197237#M36985</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;65 records in ds1. So 65 emails should go out. But, only 64 are going out &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Jun 2015 15:27:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Email-Macro-Issue/m-p/197237#M36985</guid>
      <dc:creator>sasmaverick</dc:creator>
      <dc:date>2015-06-01T15:27:27Z</dc:date>
    </item>
    <item>
      <title>Re: Email Macro-Issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Email-Macro-Issue/m-p/197238#M36986</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have you tried adding a RUN; statement to end your final DATA step?&amp;nbsp; SAS usually picks up on this sort of thing ... but since we don't have the context here that might be a possibility.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Jun 2015 15:36:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Email-Macro-Issue/m-p/197238#M36986</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-06-01T15:36:43Z</dc:date>
    </item>
    <item>
      <title>Re: Email Macro-Issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Email-Macro-Issue/m-p/197239#M36987</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Look at where you are setting &amp;amp;cnt.&lt;/P&gt;&lt;P&gt;Since that variable controls the number of iterations that would be a very likely place for an off by one error.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Jun 2015 15:52:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Email-Macro-Issue/m-p/197239#M36987</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-06-01T15:52:00Z</dc:date>
    </item>
    <item>
      <title>Re: Email Macro-Issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Email-Macro-Issue/m-p/197240#M36988</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What does options mlogic mprint symbolgen; state in the log?&amp;nbsp; As ballardw has stated &amp;amp;cnt. would appear to be wrong, if indeed there are that many rows in your dataset.&amp;nbsp; Its hard for us to say as we have no data, nor the program.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Jun 2015 17:06:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Email-Macro-Issue/m-p/197240#M36988</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-06-01T17:06:44Z</dc:date>
    </item>
    <item>
      <title>Re: Email Macro-Issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Email-Macro-Issue/m-p/197241#M36989</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As others have suggested the clue is that the macro variable 'cnt'&lt;/P&gt;&lt;P&gt;appears to be equal to the number of obs of the data set you are reading, named 'ds1'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is a style issue in macros: accessing global macro variables,&lt;/P&gt;&lt;P&gt;for which the reader has no knowledge.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;better: fetch nobs at the top of the macro&lt;/P&gt;&lt;P&gt;I recommend cut&amp;amp;paste the code from macro nobs&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.sascommunity.org/wiki/Macro_nobs" title="http://www.sascommunity.org/wiki/Macro_nobs"&gt;Macro nobs - sasCommunity&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I support RW9's suggestion of using call execute.&lt;/P&gt;&lt;P&gt;which, btw, can be run in open code, no macro needed.&lt;/P&gt;&lt;P&gt;so the code generated is obvious, i.e. has line numbers &lt;/P&gt;&lt;P&gt;and NOBS read from DS1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;place the code for the email in a separate program send-email.sas&lt;/P&gt;&lt;P&gt;so you can test it independently of the loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;here is the routine:&lt;/P&gt;&lt;P&gt;data _null_&lt;/P&gt;&lt;P&gt;set ds1&lt;/P&gt;&lt;P&gt;call execute(%nrstr('%let parm1=...;) );&lt;/P&gt;&lt;P&gt;call execute(%nrstr('%let parm2=...;) );&lt;/P&gt;&lt;P&gt;call execute(%nrstr("%include 'send-email.sas';")&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;macro function %nrstr is necessary in order to align the macro assignments with the %include&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Jun 2015 13:06:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Email-Macro-Issue/m-p/197241#M36989</guid>
      <dc:creator>Ron_MacroMaven</dc:creator>
      <dc:date>2015-06-02T13:06:15Z</dc:date>
    </item>
    <item>
      <title>Re: Email Macro-Issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Email-Macro-Issue/m-p/197242#M36990</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;Thanks for all your replies. I was missing the run statement at the end of the final data step. Thank you Astounding (user)!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Jun 2015 13:15:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Email-Macro-Issue/m-p/197242#M36990</guid>
      <dc:creator>sasmaverick</dc:creator>
      <dc:date>2015-06-02T13:15:18Z</dc:date>
    </item>
  </channel>
</rss>

