<?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: Sum lagged values in a panel dataset in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Sum-lagged-values-in-a-panel-dataset/m-p/623771#M19993</link>
    <description>&lt;P&gt;Just add a little by-group processing to the solution for &lt;A href="https://communities.sas.com/t5/New-SAS-User/Sum-values-in-lagged-years/m-p/623759" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/New-SAS-User/Sum-values-in-lagged-years/m-p/623759&lt;/A&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by firmid;
if first.firmid
then l_count = 1;
else l_count + 1;
l_count1 = lag(count);
l_count2 = lag2(count);
l_count3 = lag3(count);
if l_count gt 3 then pre3 = l_count1 + l_count2 + l_count3;
drop l_:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 11 Feb 2020 06:41:20 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-02-11T06:41:20Z</dc:date>
    <item>
      <title>Sum lagged values in a panel dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sum-lagged-values-in-a-panel-dataset/m-p/623767#M19992</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a panel dataset like below.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input FirmID $ Year Count;
datalines;
1001        1992          1
1001        1993          2
1001        1994          3
1001        1995          4
1001        1996          5
1001        1997          5
1002        1992          6
1002        1993          7
1002        1994          8
1002        1995          9
1002        1996          8
1002        1997          7
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to get the sum of the count in the previous 3 years. For example, Pre3 in 1995 is 6 (1+2+3). The result I want is below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FirmID&amp;nbsp; &amp;nbsp; &amp;nbsp; Year&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Count&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Pre3&lt;/P&gt;&lt;P&gt;1001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1992&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;1001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1993&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;1001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1994&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;1001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1995&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&lt;/P&gt;&lt;P&gt;1001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1996&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 9&lt;/P&gt;&lt;P&gt;1001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1997&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12&lt;/P&gt;&lt;P&gt;1002&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1992&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;BR /&gt;1002&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1993&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;BR /&gt;1002&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1994&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;BR /&gt;1002&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1995&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 9&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 21&lt;BR /&gt;1002&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1996&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 24&lt;BR /&gt;1002&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1997&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 25&lt;/P&gt;&lt;P&gt;&lt;CODE class="  language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class="  language-sas"&gt;What program do I need to use?&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class="  language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class="  language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2020 06:36:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sum-lagged-values-in-a-panel-dataset/m-p/623767#M19992</guid>
      <dc:creator>dapenDaniel</dc:creator>
      <dc:date>2020-02-11T06:36:24Z</dc:date>
    </item>
    <item>
      <title>Re: Sum lagged values in a panel dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sum-lagged-values-in-a-panel-dataset/m-p/623771#M19993</link>
      <description>&lt;P&gt;Just add a little by-group processing to the solution for &lt;A href="https://communities.sas.com/t5/New-SAS-User/Sum-values-in-lagged-years/m-p/623759" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/New-SAS-User/Sum-values-in-lagged-years/m-p/623759&lt;/A&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by firmid;
if first.firmid
then l_count = 1;
else l_count + 1;
l_count1 = lag(count);
l_count2 = lag2(count);
l_count3 = lag3(count);
if l_count gt 3 then pre3 = l_count1 + l_count2 + l_count3;
drop l_:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Feb 2020 06:41:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sum-lagged-values-in-a-panel-dataset/m-p/623771#M19993</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-02-11T06:41:20Z</dc:date>
    </item>
    <item>
      <title>Re: Sum lagged values in a panel dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Sum-lagged-values-in-a-panel-dataset/m-p/623772#M19994</link>
      <description>&lt;P&gt;Thank you,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2020 06:43:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Sum-lagged-values-in-a-panel-dataset/m-p/623772#M19994</guid>
      <dc:creator>dapenDaniel</dc:creator>
      <dc:date>2020-02-11T06:43:01Z</dc:date>
    </item>
  </channel>
</rss>

