<?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: Arithmetic calculation that involved data from different rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-that-involved-data-from-different-rows/m-p/136768#M27680</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's an easy solution that assumes you have only one observation within a quarter:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if qtr(date)=1 then delta_eps = eps - lag(eps);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; else if qtr(date)=2 then delta_eps = eps - lag(eps);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; else if qtr(date)=3 then delta_eps = eps - lag(eps);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; else if qtr(date)=4 then delta_eps = eps - lag(eps);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Unfortunately, understanding why it works requires digging into the complexities of the LAG function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 04 Dec 2014 19:35:15 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2014-12-04T19:35:15Z</dc:date>
    <item>
      <title>Arithmetic calculation that involved data from different rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-that-involved-data-from-different-rows/m-p/136767#M27679</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm trying to do an arithmetic calculation in which I calculate ΔEPS as&amp;nbsp; the current EPS minus the EPS&amp;nbsp; from the same quarter a year earlier.&lt;/P&gt;&lt;P&gt;For example at 31/03/2013 the ΔEPS = 20 - 5 = 15.&lt;/P&gt;&lt;P&gt;Any idea which kind of statements could execute this kind of calculation?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Lior&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 223px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl63" height="20" width="79"&gt;Date&lt;/TD&gt;&lt;TD class="xl63" width="72"&gt;EPS&lt;/TD&gt;&lt;TD class="xl64" width="72"&gt;ΔEPS&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl67" height="20"&gt;&lt;SPAN style="color: #ff00ff;"&gt;31/03/2012&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD class="xl68"&gt;&lt;SPAN style="color: #ff00ff;"&gt;5&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl65" height="20"&gt;30/06/2012&lt;/TD&gt;&lt;TD class="xl63"&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl65" height="20"&gt;30/09/2012&lt;/TD&gt;&lt;TD class="xl63"&gt;15&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl65" height="20"&gt;31/12/2012&lt;/TD&gt;&lt;TD class="xl63"&gt;17&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl67" height="20"&gt;&lt;SPAN style="color: #ff00ff;"&gt;31/03/2013&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD class="xl68"&gt;&lt;SPAN style="color: #ff00ff;"&gt;20&lt;/SPAN&gt;&lt;/TD&gt;&lt;TD class="xl66"&gt;&lt;SPAN style="color: #ff00ff;"&gt;15&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl65" height="20"&gt;30/06/2013&lt;/TD&gt;&lt;TD class="xl63"&gt;22&lt;/TD&gt;&lt;TD class="xl64"&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl65" height="20"&gt;30/09/2013&lt;/TD&gt;&lt;TD class="xl63"&gt;25&lt;/TD&gt;&lt;TD class="xl64"&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl65" height="20"&gt;31/12/2013&lt;/TD&gt;&lt;TD class="xl63"&gt;27&lt;/TD&gt;&lt;TD class="xl64"&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl65" height="20"&gt;31/03/2014&lt;/TD&gt;&lt;TD class="xl63"&gt;28&lt;/TD&gt;&lt;TD class="xl64"&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl65" height="20"&gt;30/06/2014&lt;/TD&gt;&lt;TD class="xl63"&gt;31&lt;/TD&gt;&lt;TD class="xl64"&gt;9&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl65" height="20"&gt;30/09/2014&lt;/TD&gt;&lt;TD class="xl63"&gt;32&lt;/TD&gt;&lt;TD class="xl64"&gt;7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl65" height="20"&gt;31/12/2014&lt;/TD&gt;&lt;TD class="xl63"&gt;35&lt;/TD&gt;&lt;TD class="xl64"&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Dec 2014 19:09:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-that-involved-data-from-different-rows/m-p/136767#M27679</guid>
      <dc:creator>lior</dc:creator>
      <dc:date>2014-12-04T19:09:56Z</dc:date>
    </item>
    <item>
      <title>Re: Arithmetic calculation that involved data from different rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-that-involved-data-from-different-rows/m-p/136768#M27680</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's an easy solution that assumes you have only one observation within a quarter:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if qtr(date)=1 then delta_eps = eps - lag(eps);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; else if qtr(date)=2 then delta_eps = eps - lag(eps);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; else if qtr(date)=3 then delta_eps = eps - lag(eps);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; else if qtr(date)=4 then delta_eps = eps - lag(eps);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Unfortunately, understanding why it works requires digging into the complexities of the LAG function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Dec 2014 19:35:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-that-involved-data-from-different-rows/m-p/136768#M27680</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2014-12-04T19:35:15Z</dc:date>
    </item>
    <item>
      <title>Re: Arithmetic calculation that involved data from different rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-that-involved-data-from-different-rows/m-p/136769#M27681</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Or an approach that explicitly matches date quarters (IF they are all end of quarter values)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; create table want as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; select a.*, (a.eps - b.eps) as deltaeps&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; from have as a left join have as b&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on a.date = intnx('qtr',b.date,4,'end');&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This has a minor advantage of not calculating in case a quarter is missing for some reason, or possibly has a date that is not the end of a quarter.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Dec 2014 21:08:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-that-involved-data-from-different-rows/m-p/136769#M27681</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2014-12-04T21:08:13Z</dc:date>
    </item>
    <item>
      <title>Re: Arithmetic calculation that involved data from different rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-that-involved-data-from-different-rows/m-p/136770#M27682</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, thanks for the quick unswer, but I forgot to add that my data set is more complicated as I have series of quarter_dates&lt;SPAN style="text-decoration: underline;"&gt; for each company&lt;/SPAN&gt;. After one series is end new series started with the same dates but with new company number,&amp;nbsp; &lt;/P&gt;&lt;P&gt;and I have to make sure that the calculation takes place only&lt;SPAN style="text-decoration: underline;"&gt; within&lt;/SPAN&gt; the same company number (meaning the results are as in this table) .&lt;/P&gt;&lt;P&gt;is this statement approch this complicity? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 337px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl65" height="20" width="114"&gt;&lt;STRONG&gt;Company_no&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl65" width="79"&gt;Date&lt;/TD&gt;&lt;TD class="xl65" width="72"&gt;EPS&lt;/TD&gt;&lt;TD class="xl66" width="72"&gt;ΔEPS&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl65" height="20"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl69"&gt;31/03/2012&lt;/TD&gt;&lt;TD class="xl70"&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl65" height="20"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67"&gt;30/06/2012&lt;/TD&gt;&lt;TD class="xl65"&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl65" height="20"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67"&gt;30/09/2012&lt;/TD&gt;&lt;TD class="xl65"&gt;15&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl65" height="20"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67"&gt;31/12/2012&lt;/TD&gt;&lt;TD class="xl65"&gt;17&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl65" height="20"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl69"&gt;31/03/2013&lt;/TD&gt;&lt;TD class="xl70"&gt;20&lt;/TD&gt;&lt;TD class="xl68"&gt;15&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl65" height="20"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67"&gt;30/06/2013&lt;/TD&gt;&lt;TD class="xl65"&gt;22&lt;/TD&gt;&lt;TD class="xl66"&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl65" height="20"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67"&gt;30/09/2013&lt;/TD&gt;&lt;TD class="xl65"&gt;25&lt;/TD&gt;&lt;TD class="xl66"&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl65" height="20"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67"&gt;31/12/2013&lt;/TD&gt;&lt;TD class="xl65"&gt;27&lt;/TD&gt;&lt;TD class="xl66"&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl65" height="20"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67"&gt;31/03/2014&lt;/TD&gt;&lt;TD class="xl65"&gt;28&lt;/TD&gt;&lt;TD class="xl66"&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl65" height="20"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67"&gt;30/06/2014&lt;/TD&gt;&lt;TD class="xl65"&gt;31&lt;/TD&gt;&lt;TD class="xl66"&gt;9&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl65" height="20"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67"&gt;30/09/2014&lt;/TD&gt;&lt;TD class="xl65"&gt;32&lt;/TD&gt;&lt;TD class="xl66"&gt;7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl65" height="20"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67"&gt;31/12/2014&lt;/TD&gt;&lt;TD class="xl65"&gt;35&lt;/TD&gt;&lt;TD class="xl66"&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl71" height="20"&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl69"&gt;31/03/2012&lt;/TD&gt;&lt;TD class="xl71"&gt;30&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl71" height="20"&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67"&gt;30/06/2012&lt;/TD&gt;&lt;TD class="xl65"&gt;33&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl71" height="20"&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67"&gt;30/09/2012&lt;/TD&gt;&lt;TD class="xl65"&gt;37&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl71" height="20"&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67"&gt;31/12/2012&lt;/TD&gt;&lt;TD class="xl65"&gt;38&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl71" height="20"&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl69"&gt;31/03/2013&lt;/TD&gt;&lt;TD class="xl71"&gt;40&lt;/TD&gt;&lt;TD class="xl66"&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl71" height="20"&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67"&gt;30/06/2013&lt;/TD&gt;&lt;TD class="xl65"&gt;43&lt;/TD&gt;&lt;TD class="xl66"&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl71" height="20"&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67"&gt;30/09/2013&lt;/TD&gt;&lt;TD class="xl65"&gt;50&lt;/TD&gt;&lt;TD class="xl66"&gt;13&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl71" height="20"&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67"&gt;31/12/2013&lt;/TD&gt;&lt;TD class="xl65"&gt;55&lt;/TD&gt;&lt;TD class="xl66"&gt;17&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl71" height="20"&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67"&gt;31/03/2014&lt;/TD&gt;&lt;TD class="xl65"&gt;56&lt;/TD&gt;&lt;TD class="xl66"&gt;16&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl71" height="20"&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67"&gt;30/06/2014&lt;/TD&gt;&lt;TD class="xl65"&gt;59&lt;/TD&gt;&lt;TD class="xl66"&gt;16&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl71" height="20"&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67"&gt;30/09/2014&lt;/TD&gt;&lt;TD class="xl65"&gt;61&lt;/TD&gt;&lt;TD class="xl66"&gt;11&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl71" height="20"&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67"&gt;31/12/2014&lt;/TD&gt;&lt;TD class="xl65"&gt;62&lt;/TD&gt;&lt;TD class="xl66"&gt;7&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Dec 2014 21:54:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-that-involved-data-from-different-rows/m-p/136770#M27682</guid>
      <dc:creator>lior</dc:creator>
      <dc:date>2014-12-04T21:54:57Z</dc:date>
    </item>
    <item>
      <title>Re: Arithmetic calculation that involved data from different rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-that-involved-data-from-different-rows/m-p/136771#M27683</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Hi, thanks for the quick unswer, but I forgot to add that my data set is more complicated as I have series of quarter_dates&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit; text-decoration: underline;"&gt; for each company&lt;/SPAN&gt;. After one series is end new series started with the same dates but with new company number, &lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;and I have to make sure that the calculation takes place only&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit; text-decoration: underline;"&gt; within&lt;/SPAN&gt; the same company number (meaning the results are as in this table) .&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;is this statement approch this complicity?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="border: 0px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;TBODY style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD class="xl65" height="20" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;" width="114"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;Company_no&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl65" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;" width="79"&gt;Date&lt;/TD&gt;&lt;TD class="xl65" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;" width="72"&gt;EPS&lt;/TD&gt;&lt;TD class="xl66" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;" width="72"&gt;ΔEPS&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD class="xl65" height="20" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl69" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;31/03/2012&lt;/TD&gt;&lt;TD class="xl70" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD class="xl65" height="20" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;30/06/2012&lt;/TD&gt;&lt;TD class="xl65" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD class="xl65" height="20" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;30/09/2012&lt;/TD&gt;&lt;TD class="xl65" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;15&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD class="xl65" height="20" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;31/12/2012&lt;/TD&gt;&lt;TD class="xl65" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;17&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD class="xl65" height="20" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl69" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;31/03/2013&lt;/TD&gt;&lt;TD class="xl70" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;20&lt;/TD&gt;&lt;TD class="xl68" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;15&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD class="xl65" height="20" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;30/06/2013&lt;/TD&gt;&lt;TD class="xl65" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;22&lt;/TD&gt;&lt;TD class="xl66" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD class="xl65" height="20" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;30/09/2013&lt;/TD&gt;&lt;TD class="xl65" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;25&lt;/TD&gt;&lt;TD class="xl66" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD class="xl65" height="20" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;31/12/2013&lt;/TD&gt;&lt;TD class="xl65" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;27&lt;/TD&gt;&lt;TD class="xl66" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD class="xl65" height="20" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;31/03/2014&lt;/TD&gt;&lt;TD class="xl65" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;28&lt;/TD&gt;&lt;TD class="xl66" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD class="xl65" height="20" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;30/06/2014&lt;/TD&gt;&lt;TD class="xl65" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;31&lt;/TD&gt;&lt;TD class="xl66" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;9&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD class="xl65" height="20" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;30/09/2014&lt;/TD&gt;&lt;TD class="xl65" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;32&lt;/TD&gt;&lt;TD class="xl66" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;7&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD class="xl65" height="20" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;31/12/2014&lt;/TD&gt;&lt;TD class="xl65" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;35&lt;/TD&gt;&lt;TD class="xl66" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD class="xl71" height="20" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl69" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;31/03/2012&lt;/TD&gt;&lt;TD class="xl71" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;30&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD class="xl71" height="20" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;30/06/2012&lt;/TD&gt;&lt;TD class="xl65" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;33&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD class="xl71" height="20" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;30/09/2012&lt;/TD&gt;&lt;TD class="xl65" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;37&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD class="xl71" height="20" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;31/12/2012&lt;/TD&gt;&lt;TD class="xl65" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;38&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD class="xl71" height="20" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl69" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;31/03/2013&lt;/TD&gt;&lt;TD class="xl71" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;40&lt;/TD&gt;&lt;TD class="xl66" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD class="xl71" height="20" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;30/06/2013&lt;/TD&gt;&lt;TD class="xl65" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;43&lt;/TD&gt;&lt;TD class="xl66" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD class="xl71" height="20" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;30/09/2013&lt;/TD&gt;&lt;TD class="xl65" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;50&lt;/TD&gt;&lt;TD class="xl66" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;13&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD class="xl71" height="20" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;31/12/2013&lt;/TD&gt;&lt;TD class="xl65" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;55&lt;/TD&gt;&lt;TD class="xl66" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;17&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD class="xl71" height="20" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;31/03/2014&lt;/TD&gt;&lt;TD class="xl65" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;56&lt;/TD&gt;&lt;TD class="xl66" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;16&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD class="xl71" height="20" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;30/06/2014&lt;/TD&gt;&lt;TD class="xl65" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;59&lt;/TD&gt;&lt;TD class="xl66" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;16&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD class="xl71" height="20" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;30/09/2014&lt;/TD&gt;&lt;TD class="xl65" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;61&lt;/TD&gt;&lt;TD class="xl66" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;11&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="border: 0px; font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;&lt;TD class="xl71" height="20" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl67" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;31/12/2014&lt;/TD&gt;&lt;TD class="xl65" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;62&lt;/TD&gt;&lt;TD class="xl66" style="padding-right: 4px; padding-left: 4px; border: 0px solid black; font-style: inherit; font-family: inherit;"&gt;7&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Dec 2014 21:55:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-that-involved-data-from-different-rows/m-p/136771#M27683</guid>
      <dc:creator>lior</dc:creator>
      <dc:date>2014-12-04T21:55:37Z</dc:date>
    </item>
    <item>
      <title>Re: Arithmetic calculation that involved data from different rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-that-involved-data-from-different-rows/m-p/136772#M27684</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I figured that ... it's not really a big deal.&amp;nbsp; What is important:&amp;nbsp; the structure of the data.&amp;nbsp; For my approach to work, the data has to be sorted by Company_no Date, there has to be a single observation per company_no/Date (never multiple, and never skipping a quarter in the middle).&amp;nbsp; It's OK if the date ranges are different for each company.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In that case:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; by company_no;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if first.company_no then counter=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; else counter + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if qtr(date)=1 then delta_eps = eps - lag(eps);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; else if qtr(date)=2 then delta_eps = eps - lag(eps);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; else if qtr(date)=3 then delta_eps = eps - lag(eps);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; else if qtr(date)=4 then delta_eps = eps - lag(eps);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if counter &amp;lt;= 4 then delta_eps=.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; drop counter;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Again, there are hidden complexities but the program as is should generate the right result.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Dec 2014 22:09:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-that-involved-data-from-different-rows/m-p/136772#M27684</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2014-12-04T22:09:33Z</dc:date>
    </item>
    <item>
      <title>Re: Arithmetic calculation that involved data from different rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-that-involved-data-from-different-rows/m-p/136773#M27685</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In my approach change the ON instruction from &lt;BR /&gt;on a.date = intnx('qtr',b.date,4,'end');&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;to&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;on a.company_id = b.company_id&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; and a.date = intnx('qtr',b.date,4,'end');&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can add as many fields as need to match on the ON clause. There is a side-affect I should mention. Currently if the data were not sorted by company_id they are likely to come out that way.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, the data do not need to be sorted. So if a process appends a new quarter at the end of an existing data set with the result that the company and dates are out of order it doesn't matter.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Dec 2014 22:33:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-that-involved-data-from-different-rows/m-p/136773#M27685</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2014-12-04T22:33:00Z</dc:date>
    </item>
    <item>
      <title>Re: Arithmetic calculation that involved data from different rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-that-involved-data-from-different-rows/m-p/136774#M27686</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thank you very much, its work great exept in companies that doesn't have a calender quarters (meaning instead of 31/03/2012, 30/06/2012, 30/09/2012 31/12/2012 their quarters are for example: 28/02/2012, 31/05/2012, 31/08/2012, 20/11/2012).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but most of my data are calender so its work fine to me.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks again,&lt;/P&gt;&lt;P&gt;Lior&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Dec 2014 00:16:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-that-involved-data-from-different-rows/m-p/136774#M27686</guid>
      <dc:creator>lior</dc:creator>
      <dc:date>2014-12-05T00:16:52Z</dc:date>
    </item>
    <item>
      <title>Re: Arithmetic calculation that involved data from different rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-that-involved-data-from-different-rows/m-p/136775#M27687</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;As in my data their are cases of &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt; skipping a quarter in the middle, I use the other method.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Thanks any way,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Lior&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Dec 2014 00:18:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-that-involved-data-from-different-rows/m-p/136775#M27687</guid>
      <dc:creator>lior</dc:creator>
      <dc:date>2014-12-05T00:18:30Z</dc:date>
    </item>
    <item>
      <title>Re: Arithmetic calculation that involved data from different rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-that-involved-data-from-different-rows/m-p/136776#M27688</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As a different Proc SQL approach:&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;infile&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;cards&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;dlm&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: purple; background: white;"&gt;'09'x&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;&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; Company_no&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Date:&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: teal; background: white;"&gt;ddmmyy10.&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp; EPS;&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;format&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; date &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: teal; background: white;"&gt;ddmmyy10.&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;&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;1&amp;nbsp;&amp;nbsp;&amp;nbsp; 31/03/2012 5&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;1&amp;nbsp;&amp;nbsp;&amp;nbsp; 30/06/2012 12&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;1&amp;nbsp;&amp;nbsp;&amp;nbsp; 30/09/2012 15&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;1&amp;nbsp;&amp;nbsp;&amp;nbsp; 31/12/2012 17&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;1&amp;nbsp;&amp;nbsp;&amp;nbsp; 31/03/2013 20&amp;nbsp;&amp;nbsp; 15&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;1&amp;nbsp;&amp;nbsp;&amp;nbsp; 30/06/2013 22&amp;nbsp;&amp;nbsp; 10&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;1&amp;nbsp;&amp;nbsp;&amp;nbsp; 30/09/2013 25&amp;nbsp;&amp;nbsp; 10&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;1&amp;nbsp;&amp;nbsp;&amp;nbsp; 31/12/2013 27&amp;nbsp;&amp;nbsp; 10&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;1&amp;nbsp;&amp;nbsp;&amp;nbsp; 31/03/2014 28&amp;nbsp;&amp;nbsp; 8&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;1&amp;nbsp;&amp;nbsp;&amp;nbsp; 30/06/2014 31&amp;nbsp;&amp;nbsp; 9&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;1&amp;nbsp;&amp;nbsp;&amp;nbsp; 30/09/2014 32&amp;nbsp;&amp;nbsp; 7&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;1&amp;nbsp;&amp;nbsp;&amp;nbsp; 31/12/2014 35&amp;nbsp;&amp;nbsp; 8&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;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 31/03/2012 30&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;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 30/06/2012 33&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;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 30/09/2012 37&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;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 31/12/2012 38&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;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 31/03/2013 40&amp;nbsp;&amp;nbsp; 10&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;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 30/06/2013 43&amp;nbsp;&amp;nbsp; 10&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;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 30/09/2013 50&amp;nbsp;&amp;nbsp; 13&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;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 31/12/2013 55&amp;nbsp;&amp;nbsp; 17&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;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 31/03/2014 56&amp;nbsp;&amp;nbsp; 16&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;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 30/06/2014 59&amp;nbsp;&amp;nbsp; 16&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;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 30/09/2014 61&amp;nbsp;&amp;nbsp; 11&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;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 31/12/2014 62&amp;nbsp;&amp;nbsp; 7&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; a.eps-eps &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; a.company_no=company_no &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; intck(&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: purple; background: white;"&gt;'qtr'&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;,date, a.date)=&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-family: 'Courier New';"&gt;4&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; Delta_EPS&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&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;Haikuo&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Dec 2014 04:38:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-that-involved-data-from-different-rows/m-p/136776#M27688</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2014-12-05T04:38:58Z</dc:date>
    </item>
  </channel>
</rss>

