<?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: Not sure how to write a macro for the following in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Not-sure-how-to-write-a-macro-for-the-following/m-p/124602#M25519</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you. I will try the code out. The example was for one secid. I have 25,000 secid where some of the secid have over 2400 weeks of loss information.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 01 Mar 2013 05:45:11 GMT</pubDate>
    <dc:creator>toddtodd</dc:creator>
    <dc:date>2013-03-01T05:45:11Z</dc:date>
    <item>
      <title>Not sure how to write a macro for the following</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Not-sure-how-to-write-a-macro-for-the-following/m-p/124599#M25516</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Also, here is an example. Lhat_t = current loss_t * tmp2 + lhat_t-1 * tmp1&lt;/P&gt;&lt;P&gt;At each week lhat is calculated based on the lhat last week and the new current loss. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 128px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD height="20" width="64"&gt;tmp1=&lt;/TD&gt;&lt;TD align="right" width="64"&gt;0.986629&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;tmp2=&lt;/TD&gt;&lt;TD align="right"&gt;0.013371&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" width="214"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl68" height="20" width="64"&gt;Weekid&lt;/TD&gt;&lt;TD class="xl68" style="border-left: none;" width="86"&gt;current Loss&lt;/TD&gt;&lt;TD class="xl68" style="border-left: none;" width="64"&gt;lhat&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl67" height="20" style="border-top: none;"&gt;1&lt;/TD&gt;&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;0.0120&lt;/TD&gt;&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;0.0120&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl67" height="20" style="border-top: none;"&gt;2&lt;/TD&gt;&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;0.0050&lt;/TD&gt;&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;0.0119&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl67" height="20" style="border-top: none;"&gt;3&lt;/TD&gt;&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;0.0000&lt;/TD&gt;&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;0.0117&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl67" height="20" style="border-top: none;"&gt;4&lt;/TD&gt;&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;0.0230&lt;/TD&gt;&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;0.0119&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl66"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;I am trying to write the code below as a loop.&lt;/P&gt;&lt;P&gt;data work.alldata_lhat;&lt;/P&gt;&lt;P&gt;set work.alldata_lhat;&lt;/P&gt;&lt;P&gt;by secid;&lt;/P&gt;&lt;P&gt;if count=1 then oldlhat=current_loss;&lt;/P&gt;&lt;P&gt;if count=1 then lhat=tmp1*oldlhat+tmp2*current_loss;&lt;/P&gt;&lt;P&gt;oldlhat=lag(lhat);if count&amp;gt; 1 then lhat=tmp1*oldlhat+tmp2*current_loss;&lt;/P&gt;&lt;P&gt;oldlhat=lag(lhat);if count&amp;gt; 2 then lhat=tmp1*oldlhat+tmp2*current_loss;&lt;/P&gt;&lt;P&gt;oldlhat=lag(lhat);if count&amp;gt; 3 then lhat=tmp1*oldlhat+tmp2*current_loss;&lt;/P&gt;&lt;P&gt;oldlhat=lag(lhat);if count&amp;gt; 4 then lhat=tmp1*oldlhat+tmp2*current_loss;&lt;/P&gt;&lt;P&gt;oldlhat=lag(lhat);if count&amp;gt; 5 then lhat=tmp1*oldlhat+tmp2*current_loss;&lt;/P&gt;&lt;P&gt;_loss;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Mar 2013 00:10:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Not-sure-how-to-write-a-macro-for-the-following/m-p/124599#M25516</guid>
      <dc:creator>toddtodd</dc:creator>
      <dc:date>2013-03-01T00:10:28Z</dc:date>
    </item>
    <item>
      <title>Re: Not sure how to write a macro for the following</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Not-sure-how-to-write-a-macro-for-the-following/m-p/124600#M25517</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If I am understanding what you need, I dont think you need a macro for this. I dont have access to SAS right this second to verify this but I think something like this will work:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;data work.alldata_lhat;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set work.alldata_lhat;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by secid;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; tmp1 = &lt;/SPAN&gt;0.986629;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tmp2 = 0.013371;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if first.secid then do;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; oldhat=current_loss;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;lhat=tmp1*oldlhat+tmp2*current_loss;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else do;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&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; oldhat=lhat;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&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; lhat&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;=tmp1*oldlhat+tmp2*current_loss;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; retain oldhat lhat;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run;&lt;/P&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Mar 2013 02:41:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Not-sure-how-to-write-a-macro-for-the-following/m-p/124600#M25517</guid>
      <dc:creator>esjackso</dc:creator>
      <dc:date>2013-03-01T02:41:23Z</dc:date>
    </item>
    <item>
      <title>Re: Not sure how to write a macro for the following</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Not-sure-how-to-write-a-macro-for-the-following/m-p/124601#M25518</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What is the question?&amp;nbsp; The code looks really strange to me.&amp;nbsp; I would have expected to see something using a RETAIN statement to carry the value forward to use in calculating the new value.&amp;nbsp; You are not using the BY statement for anything.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data old;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; input Weekid current_Loss want ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; secid=1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;cards;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;1 0.0120 0.0120&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;2 0.0050 0.0119&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;3 0.0000 0.0117&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;4 0.0230 0.0119&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;;;;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data new;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; retain tmp1 0.986629 tmp2 0.013371 ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; set old;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; by secid ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; if first.secid then oldhat=current_loss;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; lhat = tmp1*oldhat + tmp2*current_loss;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; output;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; oldhat=lhat;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; retain oldhat ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;ID CURRENT_LOSS LHAT&amp;nbsp;&amp;nbsp; WANT&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;1 0.012 0.012&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.012&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;2 0.005 0.011906403&amp;nbsp; 0.0119&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;3 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.0117472025 0.0117&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;4 0.023 0.0118976636 0.0119&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want to turn it into a macro then what part of the above changes?&amp;nbsp; Is it the constants used in the formula?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Mar 2013 02:41:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Not-sure-how-to-write-a-macro-for-the-following/m-p/124601#M25518</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-03-01T02:41:54Z</dc:date>
    </item>
    <item>
      <title>Re: Not sure how to write a macro for the following</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Not-sure-how-to-write-a-macro-for-the-following/m-p/124602#M25519</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you. I will try the code out. The example was for one secid. I have 25,000 secid where some of the secid have over 2400 weeks of loss information.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Mar 2013 05:45:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Not-sure-how-to-write-a-macro-for-the-following/m-p/124602#M25519</guid>
      <dc:creator>toddtodd</dc:creator>
      <dc:date>2013-03-01T05:45:11Z</dc:date>
    </item>
  </channel>
</rss>

