<?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: Rolling cumulative Earnings for 4 quarters for different CUSIP in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Rolling-cumulative-Earnings-for-4-quarters-for-different-CUSIP/m-p/540347#M149039</link>
    <description>Let's see if a non macro solution generates what you are seeking.  After sorting:&lt;BR /&gt;&lt;BR /&gt;data want ; &lt;BR /&gt;set have;&lt;BR /&gt;by cusip;&lt;BR /&gt;if first.cusip then do;&lt;BR /&gt;  N=1;&lt;BR /&gt;  RE =0;&lt;BR /&gt;end;&lt;BR /&gt;else N+1;&lt;BR /&gt;back5 = lag5(epspiq);&lt;BR /&gt;RE + epspiq;&lt;BR /&gt;if N &amp;gt; 4 then RE = RE - back5;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;See how this compares with your expectations.  It might be an exact match, a rolling sum of earnings for the most recent 4 quarters.</description>
    <pubDate>Tue, 05 Mar 2019 07:24:08 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2019-03-05T07:24:08Z</dc:date>
    <item>
      <title>Rolling cumulative Earnings for 4 quarters for different CUSIP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-cumulative-Earnings-for-4-quarters-for-different-CUSIP/m-p/540324#M149028</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'd like to calculate rolling cumulative 4 quarters of earnings (for different cusip).&lt;/P&gt;&lt;P&gt;Currently this is the code I use:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro mom(datain=); 
%do iter=1 %to 3; 
proc sort data=&amp;amp;datain; by cusip line; run; 
data &amp;amp;datain; set &amp;amp;datain; by cusip; 
if &amp;amp;iter&amp;lt;=1 then C2E=C2E+lag(epspiq); 
if &amp;amp;iter&amp;lt;=2 then C3E=C3E+lag&amp;amp;iter(epspiq); 
if &amp;amp;iter&amp;lt;=3 then C4E=C4E+lag&amp;amp;iter(epspiq); 
run; 
%end; 
%mend; 
%mom(datain=com);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It works well for the first cusip, however since the second cusip, it takes the lag of earnings from the previous cusip, which is not correct.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please kindly advise.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm fine to use other procedures and not only macro procedure.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Mar 2019 05:03:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-cumulative-Earnings-for-4-quarters-for-different-CUSIP/m-p/540324#M149028</guid>
      <dc:creator>janed</dc:creator>
      <dc:date>2019-03-05T05:03:04Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling cumulative Earnings for 4 quarters for different CUSIP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-cumulative-Earnings-for-4-quarters-for-different-CUSIP/m-p/540347#M149039</link>
      <description>Let's see if a non macro solution generates what you are seeking.  After sorting:&lt;BR /&gt;&lt;BR /&gt;data want ; &lt;BR /&gt;set have;&lt;BR /&gt;by cusip;&lt;BR /&gt;if first.cusip then do;&lt;BR /&gt;  N=1;&lt;BR /&gt;  RE =0;&lt;BR /&gt;end;&lt;BR /&gt;else N+1;&lt;BR /&gt;back5 = lag5(epspiq);&lt;BR /&gt;RE + epspiq;&lt;BR /&gt;if N &amp;gt; 4 then RE = RE - back5;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;See how this compares with your expectations.  It might be an exact match, a rolling sum of earnings for the most recent 4 quarters.</description>
      <pubDate>Tue, 05 Mar 2019 07:24:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-cumulative-Earnings-for-4-quarters-for-different-CUSIP/m-p/540347#M149039</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-03-05T07:24:08Z</dc:date>
    </item>
  </channel>
</rss>

