<?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 of variables from t-2 to t in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Sum-of-variables-from-t-2-to-t/m-p/190915#M48104</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you to all the helpers,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think Peter's solution is the simplest perhaps. I have another problem is that not all the observations with non-missing fyear+1 and fyear+2. In order to mitigate this problem and to ensure all the gvkey with non-missing years, I perform the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table a as&lt;/P&gt;&lt;P&gt; select * &lt;/P&gt;&lt;P&gt;&amp;nbsp; from (select distinct FYEAR from SAMPLEDATA), &lt;/P&gt;&lt;P&gt;(select distinct GVKEY from SAMPLEDATA) ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt; merge a SAMPLEDATA;&lt;/P&gt;&lt;P&gt; by&amp;nbsp; gvkey&amp;nbsp; FYEAR;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, if I wish to exclude missing observations from a given year, how should I do that? For example, if I wish to compute the sum_txpd3 for a given gvkey for year 2013, I must have non-missing txpd for year 2011, 2012 and 2013. If the data for 2012 is missing, then the sum_txpd3 should be left as ".". With the code given by Peter, the the total of txpd for years 2011 to 2013 still will be calculated even if there is one missing txpd, lets say 2012.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;MSPAK&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 04 Dec 2014 02:45:53 GMT</pubDate>
    <dc:creator>mspak</dc:creator>
    <dc:date>2014-12-04T02:45:53Z</dc:date>
    <item>
      <title>Sum of variables from t-2 to t</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sum-of-variables-from-t-2-to-t/m-p/190909#M48098</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to compute the total of a variable starting from t-2 to t for a company (gvkey). It seems that proc expand can perform time series total from lag variables. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My data (attached)&amp;nbsp; is presented as follows:&lt;/P&gt;&lt;P&gt;GVKEY&amp;nbsp;&amp;nbsp;&amp;nbsp; FYEAR&amp;nbsp;&amp;nbsp; TXPD&lt;/P&gt;&lt;P&gt;001004&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1995&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5.3&lt;/P&gt;&lt;P&gt;001004&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1996&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8.6&lt;/P&gt;&lt;P&gt;001004&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1997&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6.2&lt;/P&gt;&lt;P&gt;001004&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1998&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;4.4&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;001004&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1999&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 11.3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;001004&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3.2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;....&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to generate a new variable, namely sum_TXPD3. The new variable is computed by totaling the TXPD for 3 years starting from t-2 to t (i.e., t-2, t-1, and t). For example, for the company with the gvkey code 001004, the&amp;nbsp; sum_TXPD3 should be blank for fyear 1995 and 1996 as there is no sufficient data to compute the variable. For the year 1997, the sum_TXPD3 should be 20.1 (5.3 + 8.6 + 6.2). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There might be some missing data in the between of the time series. For example, if the fyear 1996 is missing, then the sum_TXPD3 for fyear 1997 should be stated as ".". &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope anyone here to help me to resolve the problem. I am not sure proc expand can help in this problem?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you in advanced.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;mspak&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 30 Nov 2014 07:02:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sum-of-variables-from-t-2-to-t/m-p/190909#M48098</guid>
      <dc:creator>mspak</dc:creator>
      <dc:date>2014-11-30T07:02:04Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of variables from t-2 to t</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sum-of-variables-from-t-2-to-t/m-p/190910#M48099</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;sum_TXPD3=TXPD+lag(TXPD)+lag2(TXPD);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 30 Nov 2014 14:08:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sum-of-variables-from-t-2-to-t/m-p/190910#M48099</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2014-11-30T14:08:26Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of variables from t-2 to t</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sum-of-variables-from-t-2-to-t/m-p/190911#M48100</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think something like the following will accomplish what you want:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set test.sampledata;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by gvkey;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if first.gvkey then counter=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else counter+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; sum_TXPD3=ifn(counter gt 2,TXPD+lag(TXPD)+lag2(TXPD),.);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 30 Nov 2014 15:04:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sum-of-variables-from-t-2-to-t/m-p/190911#M48100</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2014-11-30T15:04:08Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of variables from t-2 to t</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sum-of-variables-from-t-2-to-t/m-p/190912#M48101</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;An SQL alternative could be (not tested):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table want as&lt;/P&gt;&lt;P&gt;select *, (select sum(TXPD) from have where gvkey=a.gvkey and fyear &amp;lt;= a.fyear having count(fyear) &amp;gt;=3) as rolling_sum&lt;/P&gt;&lt;P&gt;from have a&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 30 Nov 2014 16:49:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sum-of-variables-from-t-2-to-t/m-p/190912#M48101</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2014-11-30T16:49:24Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of variables from t-2 to t</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sum-of-variables-from-t-2-to-t/m-p/190913#M48102</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There are a number of similar questions posted in the forums over time. Searching for "rolling" provided links to interesting solutions.&lt;/P&gt;&lt;P&gt;I don't think an sql approach has bein proposed - perhaps because it would be impossible to expand much beyond 10 period lag.&lt;/P&gt;&lt;P&gt;Select a.*, (a.txpd,b.txpd,c.txpd) as sum_txpd3&lt;/P&gt;&lt;P&gt;from sampledata a&lt;/P&gt;&lt;P&gt;left join sampledata b&lt;/P&gt;&lt;P&gt;on&amp;nbsp; a.gvkey EQ b.gvkey&lt;/P&gt;&lt;P&gt;and a.fyear EQ (b.fyear+1)&lt;/P&gt;&lt;P&gt;left join sampledata c&lt;/P&gt;&lt;P&gt;on a.gvkey EQ c.gvkey&lt;/P&gt;&lt;P&gt;and a.fyear EQ (c.fyear+2)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 30 Nov 2014 19:40:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sum-of-variables-from-t-2-to-t/m-p/190913#M48102</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2014-11-30T19:40:38Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of variables from t-2 to t</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sum-of-variables-from-t-2-to-t/m-p/190914#M48103</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I hear ya. &lt;img id="smileywink" class="emoticon emoticon-smileywink" src="https://communities.sas.com/i/smilies/16x16_smiley-wink.png" alt="Smiley Wink" title="Smiley Wink" /&gt;&amp;nbsp; &lt;A __default_attr="392339" __jive_macro_name="user" class="jive_macro jive_macro_user" href="https://communities.sas.com/"&gt;&lt;/A&gt; reminded me that my solution was flawed, and it was, here is another try:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;proc sql;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;create table want as&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;select *, (select sum(TXPD) from have where gvkey=a.gvkey and &lt;STRONG&gt;a.fear-2&amp;lt;=&lt;/STRONG&gt; fyear &amp;lt;= a.fyear having count(&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13.3333330154419px; background-color: #ffffff;"&gt;TXPD&lt;/SPAN&gt;) &lt;STRONG&gt;=3&lt;/STRONG&gt;) as rolling_sum&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;from have a&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Dec 2014 00:17:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sum-of-variables-from-t-2-to-t/m-p/190914#M48103</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2014-12-01T00:17:32Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of variables from t-2 to t</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sum-of-variables-from-t-2-to-t/m-p/190915#M48104</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you to all the helpers,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think Peter's solution is the simplest perhaps. I have another problem is that not all the observations with non-missing fyear+1 and fyear+2. In order to mitigate this problem and to ensure all the gvkey with non-missing years, I perform the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table a as&lt;/P&gt;&lt;P&gt; select * &lt;/P&gt;&lt;P&gt;&amp;nbsp; from (select distinct FYEAR from SAMPLEDATA), &lt;/P&gt;&lt;P&gt;(select distinct GVKEY from SAMPLEDATA) ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt; merge a SAMPLEDATA;&lt;/P&gt;&lt;P&gt; by&amp;nbsp; gvkey&amp;nbsp; FYEAR;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, if I wish to exclude missing observations from a given year, how should I do that? For example, if I wish to compute the sum_txpd3 for a given gvkey for year 2013, I must have non-missing txpd for year 2011, 2012 and 2013. If the data for 2012 is missing, then the sum_txpd3 should be left as ".". With the code given by Peter, the the total of txpd for years 2011 to 2013 still will be calculated even if there is one missing txpd, lets say 2012.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;MSPAK&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Dec 2014 02:45:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sum-of-variables-from-t-2-to-t/m-p/190915#M48104</guid>
      <dc:creator>mspak</dc:creator>
      <dc:date>2014-12-04T02:45:53Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of variables from t-2 to t</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sum-of-variables-from-t-2-to-t/m-p/190916#M48105</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have you actually tried my suggestion? Not bragging here, but it seems to me that m&lt;SPAN style="font-size: 13.3333330154419px; line-height: 1.5em;"&gt;y code is &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;1)&amp;nbsp; more dynamic and flexible, you can change parameters to fit your different range, such as 10 years, 100 years etc. 2). is capable to deal with the missing value to meet your criteria. See below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;input&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; GVKEY $&amp;nbsp;&amp;nbsp; FYEAR TXPD;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;cards&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;001004&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1995 5.3&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;001004&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1996 8.6&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;001004&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1997 6.2&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;001004&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1998 4.4&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;001004&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1999 11.3&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;001004&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2000 .&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;001004&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2001 3.2&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;001004&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2002 3.2&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;001004&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2003 3.2&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;001004&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2004 3.2&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;sql&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;create&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;table&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; want &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;as&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; *, (&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; sum(TXPD) &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; have &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;where&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; gvkey=a.gvkey &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;and&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; a.fyear-&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-family: 'Courier New';"&gt;2&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;&amp;lt;= fyear &amp;lt;= a.fyear &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;having&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; count(TXPD) =&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-family: 'Courier New';"&gt;3&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;) &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; rolling_sum&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&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; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; have a&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;quit&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;Only those with non-missing value for 3 continuous years are computed, else are left missing as you have requested. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;Haikuo&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Dec 2014 03:17:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sum-of-variables-from-t-2-to-t/m-p/190916#M48105</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2014-12-04T03:17:36Z</dc:date>
    </item>
  </channel>
</rss>

