<?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: Lag Function within By-Group Processing in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Lag-Function-within-By-Group-Processing/m-p/105140#M21931</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Following Tom's idea, while using ifn(), which unconditionally lagging:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by state;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain&amp;nbsp; Modeled_Vacancy;&lt;/P&gt;&lt;P&gt;Modeled_Vacancy=ifn(first.state, Initial_Vrate,&amp;nbsp; Modeled_Vacancy + &amp;amp;intercept. + (&amp;amp;unemployment. *lag(urate)) + (&amp;amp;permits. *lag(bp)));&lt;/P&gt;&lt;P&gt;format Modeled_Vacancy percent8.1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 20 Dec 2012 04:42:18 GMT</pubDate>
    <dc:creator>Haikuo</dc:creator>
    <dc:date>2012-12-20T04:42:18Z</dc:date>
    <item>
      <title>Lag Function within By-Group Processing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lag-Function-within-By-Group-Processing/m-p/105138#M21929</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey SAS'ers,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I'm trying to use a lag function within by groups. please see my desired output for an idea of what i'm going for.&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*Begin Code*/&lt;/P&gt;&lt;P&gt;%let intercept = 0.236917;&lt;/P&gt;&lt;P&gt;%let unemployment = 0.010734;&lt;/P&gt;&lt;P&gt;%let permits = -0.03398;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data Have;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input&amp;nbsp; State $ i urate bp date Initial_Vrate;&lt;/P&gt;&lt;P&gt;&amp;nbsp; informat State $10. i urate bp&amp;nbsp; date&amp;nbsp; Initial_Vrate&amp;nbsp; Best12.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format date monyy. urate Initial_Vrate percent8.2;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;Alabama 1 0.11766 6.78106 18263 0.13061&lt;/P&gt;&lt;P&gt;Alabama 2 0.11367 6.77765 18294 0.13061&lt;/P&gt;&lt;P&gt;Alabama 3 0.10847 7.20266 18322 0.13061&lt;/P&gt;&lt;P&gt;Alabama 4 0.09303 7.04054 18353 0.13061&lt;/P&gt;&lt;P&gt;Alabama 5 0.09025 6.96319 18383 0.13061&lt;/P&gt;&lt;P&gt;Alaska 1 0.09307 3.17805 18263 0.14659&lt;/P&gt;&lt;P&gt;Alaska 2 0.09553 3.80666 18294 0.14659&lt;/P&gt;&lt;P&gt;Alaska 3 0.09407 3.82864 18322 0.14659&lt;/P&gt;&lt;P&gt;Alaska 4 0.08254 4.60517 18353 0.14659&lt;/P&gt;&lt;P&gt;Alaska 5 0.07608 5.05625 18383 0.14659&lt;/P&gt;&lt;P&gt;Arizona 1 0.09728 7.13728 18263 0.1616&lt;/P&gt;&lt;P&gt;Arizona 2 0.09774 7.02198 18294 0.1616&lt;/P&gt;&lt;P&gt;Arizona 3 0.09384 7.42536 18322 0.1616&lt;/P&gt;&lt;P&gt;Arizona 4 0.09727 7.04054 18353 0.1616&lt;/P&gt;&lt;P&gt;Arizona 5 0.09691 6.88244 18383 0.1616&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by state;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if first.state then Modeled_Vacancy = Initial_Vrate;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else Modeled_Vacancy = lag(Modeled_Vacancy) + &amp;amp;intercept. + (&amp;amp;unemployment. *lag(urate)) + (&amp;amp;permits. *lag(bp));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; format Modeled_Vacancy percent8.2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* End of Code - Output should look like the following: */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" width="507"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD height="20" width="64"&gt;State&lt;/TD&gt;&lt;TD width="64"&gt;i&lt;/TD&gt;&lt;TD width="64"&gt;urate&lt;/TD&gt;&lt;TD width="64"&gt;bp&lt;/TD&gt;&lt;TD width="64"&gt;date&lt;/TD&gt;&lt;TD width="82"&gt;initial_vrate&lt;/TD&gt;&lt;TD width="105"&gt;Modeled_Vrate&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20" width="64"&gt;Alabama&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-left: none;" width="64"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl66" style="border-left: none;" width="64"&gt;11.8%&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-left: none;" width="64"&gt;6.78106&lt;/TD&gt;&lt;TD align="right" class="xl67" style="border-left: none;" width="64"&gt;Jan-10&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-left: none;" width="82"&gt;13.1%&lt;/TD&gt;&lt;TD align="right" class="xl68"&gt;13.1%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20" style="border-top: none;" width="64"&gt;Alabama&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;" width="64"&gt;2&lt;/TD&gt;&lt;TD align="right" class="xl66" style="border-top: none; border-left: none;" width="64"&gt;11.4%&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;" width="64"&gt;6.77765&lt;/TD&gt;&lt;TD align="right" class="xl67" style="border-top: none; border-left: none;" width="64"&gt;Feb-10&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;" width="82"&gt;13.1%&lt;/TD&gt;&lt;TD align="right" class="xl69"&gt;13.8%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20" style="border-top: none;" width="64"&gt;Alabama&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;" width="64"&gt;3&lt;/TD&gt;&lt;TD align="right" class="xl66" style="border-top: none; border-left: none;" width="64"&gt;10.8%&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;" width="64"&gt;7.20266&lt;/TD&gt;&lt;TD align="right" class="xl67" style="border-top: none; border-left: none;" width="64"&gt;Mar-10&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;" width="82"&gt;13.1%&lt;/TD&gt;&lt;TD align="right" class="xl69"&gt;14.6%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20" style="border-top: none;" width="64"&gt;Alabama&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;" width="64"&gt;4&lt;/TD&gt;&lt;TD align="right" class="xl66" style="border-top: none; border-left: none;" width="64"&gt;9.3%&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;" width="64"&gt;7.04054&lt;/TD&gt;&lt;TD align="right" class="xl67" style="border-top: none; border-left: none;" width="64"&gt;Apr-10&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;" width="82"&gt;13.1%&lt;/TD&gt;&lt;TD align="right" class="xl69"&gt;14.0%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20" style="border-top: none;" width="64"&gt;Alabama&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;" width="64"&gt;5&lt;/TD&gt;&lt;TD align="right" class="xl66" style="border-top: none; border-left: none;" width="64"&gt;9.0%&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;" width="64"&gt;6.96319&lt;/TD&gt;&lt;TD align="right" class="xl67" style="border-top: none; border-left: none;" width="64"&gt;May-10&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;" width="82"&gt;13.1%&lt;/TD&gt;&lt;TD align="right" class="xl69"&gt;13.8%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20" style="border-top: none;" width="64"&gt;Alaska&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;" width="64"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl66" style="border-top: none; border-left: none;" width="64"&gt;9.3%&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;" width="64"&gt;3.17805&lt;/TD&gt;&lt;TD align="right" class="xl67" style="border-top: none; border-left: none;" width="64"&gt;Jan-10&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;" width="82"&gt;14.7%&lt;/TD&gt;&lt;TD align="right" class="xl68"&gt;14.7%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20" style="border-top: none;" width="64"&gt;Alaska&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;" width="64"&gt;2&lt;/TD&gt;&lt;TD align="right" class="xl66" style="border-top: none; border-left: none;" width="64"&gt;9.6%&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;" width="64"&gt;3.80666&lt;/TD&gt;&lt;TD align="right" class="xl67" style="border-top: none; border-left: none;" width="64"&gt;Feb-10&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;" width="82"&gt;14.7%&lt;/TD&gt;&lt;TD align="right" class="xl69"&gt;27.7%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20" style="border-top: none;" width="64"&gt;Alaska&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;" width="64"&gt;3&lt;/TD&gt;&lt;TD align="right" class="xl66" style="border-top: none; border-left: none;" width="64"&gt;9.4%&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;" width="64"&gt;3.82864&lt;/TD&gt;&lt;TD align="right" class="xl67" style="border-top: none; border-left: none;" width="64"&gt;Mar-10&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;" width="82"&gt;14.7%&lt;/TD&gt;&lt;TD align="right" class="xl69"&gt;38.5%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20" style="border-top: none;" width="64"&gt;Alaska&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;" width="64"&gt;4&lt;/TD&gt;&lt;TD align="right" class="xl66" style="border-top: none; border-left: none;" width="64"&gt;8.3%&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;" width="64"&gt;4.60517&lt;/TD&gt;&lt;TD align="right" class="xl67" style="border-top: none; border-left: none;" width="64"&gt;Apr-10&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;" width="82"&gt;14.7%&lt;/TD&gt;&lt;TD align="right" class="xl69"&gt;49.3%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20" style="border-top: none;" width="64"&gt;Alaska&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;" width="64"&gt;5&lt;/TD&gt;&lt;TD align="right" class="xl66" style="border-top: none; border-left: none;" width="64"&gt;7.6%&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;" width="64"&gt;5.05625&lt;/TD&gt;&lt;TD align="right" class="xl67" style="border-top: none; border-left: none;" width="64"&gt;May-10&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;" width="82"&gt;14.7%&lt;/TD&gt;&lt;TD align="right" class="xl69"&gt;57.4%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20" style="border-top: none;" width="64"&gt;Arizona&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;" width="64"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl66" style="border-top: none; border-left: none;" width="64"&gt;9.7%&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;" width="64"&gt;7.13728&lt;/TD&gt;&lt;TD align="right" class="xl67" style="border-top: none; border-left: none;" width="64"&gt;Jan-10&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;" width="82"&gt;16.2%&lt;/TD&gt;&lt;TD align="right" class="xl68"&gt;16.2%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20" style="border-top: none;" width="64"&gt;Arizona&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;" width="64"&gt;2&lt;/TD&gt;&lt;TD align="right" class="xl66" style="border-top: none; border-left: none;" width="64"&gt;9.8%&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;" width="64"&gt;7.02198&lt;/TD&gt;&lt;TD align="right" class="xl67" style="border-top: none; border-left: none;" width="64"&gt;Feb-10&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;" width="82"&gt;16.2%&lt;/TD&gt;&lt;TD align="right" class="xl69"&gt;15.7%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20" style="border-top: none;" width="64"&gt;Arizona&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;" width="64"&gt;3&lt;/TD&gt;&lt;TD align="right" class="xl66" style="border-top: none; border-left: none;" width="64"&gt;9.4%&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;" width="64"&gt;7.42536&lt;/TD&gt;&lt;TD align="right" class="xl67" style="border-top: none; border-left: none;" width="64"&gt;Mar-10&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;" width="82"&gt;16.2%&lt;/TD&gt;&lt;TD align="right" class="xl69"&gt;15.6%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20" style="border-top: none;" width="64"&gt;Arizona&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;" width="64"&gt;4&lt;/TD&gt;&lt;TD align="right" class="xl66" style="border-top: none; border-left: none;" width="64"&gt;9.7%&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;" width="64"&gt;7.04054&lt;/TD&gt;&lt;TD align="right" class="xl67" style="border-top: none; border-left: none;" width="64"&gt;Apr-10&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;" width="82"&gt;16.2%&lt;/TD&gt;&lt;TD align="right" class="xl69"&gt;14.2%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20" style="border-top: none;" width="64"&gt;Arizona&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;" width="64"&gt;5&lt;/TD&gt;&lt;TD align="right" class="xl66" style="border-top: none; border-left: none;" width="64"&gt;9.7%&lt;/TD&gt;&lt;TD align="right" class="xl64" style="border-top: none; border-left: none;" width="64"&gt;6.88244&lt;/TD&gt;&lt;TD align="right" class="xl67" style="border-top: none; border-left: none;" width="64"&gt;May-10&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;" width="82"&gt;16.2%&lt;/TD&gt;&lt;TD align="right" class="xl69"&gt;14.1%&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Dec 2012 02:55:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lag-Function-within-By-Group-Processing/m-p/105138#M21929</guid>
      <dc:creator>SAShole</dc:creator>
      <dc:date>2012-12-20T02:55:22Z</dc:date>
    </item>
    <item>
      <title>Re: Lag Function within By-Group Processing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lag-Function-within-By-Group-Processing/m-p/105139#M21930</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do NOT call LAG() function conditionally.&amp;nbsp; Search for the thousands of threads that explain how LAG() works.&lt;/P&gt;&lt;P&gt;For your example you might be able to solve this by putting the IF FIRST..... statement AFTER the one that uses the lagged values. &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;&lt;SPAN style="font-family: 'courier new', courier;"&gt;Modeled_Vacancy = lag(Modeled_Vacancy) + &amp;amp;intercept. + (&amp;amp;unemployment. *lag(urate)) + (&amp;amp;permits. *lag(bp));&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;if first.state then Modeled_Vacancy = Initial_Vrate;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Not sure about how LAG() works for a calculated variable.&amp;nbsp; You might want to just RETAIN the value instead.&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;&lt;SPAN style="font-family: 'courier new', courier;"&gt;retain modeled_vacancy ;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;Modeled_Vacancy = Modeled_Vacancy + &amp;amp;intercept. + (&amp;amp;unemployment. *lag(urate)) + (&amp;amp;permits. *lag(bp));&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;if first.state then Modeled_Vacancy = Initial_Vrate;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Dec 2012 03:15:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lag-Function-within-By-Group-Processing/m-p/105139#M21930</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-12-20T03:15:25Z</dc:date>
    </item>
    <item>
      <title>Re: Lag Function within By-Group Processing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lag-Function-within-By-Group-Processing/m-p/105140#M21931</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Following Tom's idea, while using ifn(), which unconditionally lagging:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by state;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain&amp;nbsp; Modeled_Vacancy;&lt;/P&gt;&lt;P&gt;Modeled_Vacancy=ifn(first.state, Initial_Vrate,&amp;nbsp; Modeled_Vacancy + &amp;amp;intercept. + (&amp;amp;unemployment. *lag(urate)) + (&amp;amp;permits. *lag(bp)));&lt;/P&gt;&lt;P&gt;format Modeled_Vacancy percent8.1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Dec 2012 04:42:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lag-Function-within-By-Group-Processing/m-p/105140#M21931</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-12-20T04:42:18Z</dc:date>
    </item>
    <item>
      <title>Re: Lag Function within By-Group Processing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lag-Function-within-By-Group-Processing/m-p/105141#M21932</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Mike explained using Lag Function with condition in the link below:&lt;/P&gt;&lt;P&gt;&lt;A _jive_internal="true" href="https://communities.sas.com/thread/35037"&gt;https://communities.sas.com/thread/35037&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Dec 2012 15:42:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lag-Function-within-By-Group-Processing/m-p/105141#M21932</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2012-12-20T15:42:32Z</dc:date>
    </item>
    <item>
      <title>Re: Lag Function within By-Group Processing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lag-Function-within-By-Group-Processing/m-p/105142#M21933</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;to answer the original posting, reverse the order of these two lines&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;if first.state then Modeled_Vacancy = Initial_Vrate;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;else Modeled_Vacancy = lag(Modeled_Vacancy) + &amp;amp;intercept. + (&amp;amp;unemployment. *lag(urate)) + (&amp;amp;permits. *lag(bp));&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;replace with&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt; Modeled_Vacancy = lag(Modeled_Vacancy) + &amp;amp;intercept. + (&amp;amp;unemployment. *lag(urate)) + (&amp;amp;permits. *lag(bp));&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;if first.state then Modeled_Vacancy = Initial_Vrate;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;that seems the simplest change that overcomes the LAG() problem&lt;/P&gt;&lt;P&gt;(notice there is now no ELSE so the LAG()s become "unconditional")&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Dec 2012 00:29:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lag-Function-within-By-Group-Processing/m-p/105142#M21933</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2012-12-21T00:29:43Z</dc:date>
    </item>
  </channel>
</rss>

