<?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: Cumulative sum around an event date by group in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Cumulative-sum-around-an-event-date-by-group/m-p/523319#M4582</link>
    <description>&lt;P&gt;Only one statement to add:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cumsums;
set edates;
do point = max(obs-5, 1) to min(obs+5, nobs);
    set have point=point nobs=nobs;
    if RIC = targetRIC then do;
        cumSum = sum(cumSum, ar);
        row = point - obs + 6;
        output;
        end;
    end;
drop targetRIC obs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note, I also corrected the third statement, because point must be greater than zero.&lt;/P&gt;</description>
    <pubDate>Sun, 23 Dec 2018 07:07:20 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2018-12-23T07:07:20Z</dc:date>
    <item>
      <title>Cumulative sum around an event date by group</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Cumulative-sum-around-an-event-date-by-group/m-p/523219#M4562</link>
      <description>&lt;P&gt;Hi people,&lt;/P&gt;&lt;P&gt;I want to do a cumulative sum start from a specific point and end at another specific point. In other words, I have a data set below. At any point where column 'edate' gets a value (for example at edate=&amp;nbsp;&lt;SPAN&gt;21-APR-2011, or&amp;nbsp;22-JUL-2011 and so on), I want to do a cumulative sum of&amp;nbsp; column 'ar' within a range of 5 rows before to 5 rows after that edate. This means the cumulative sum will start from the 5th row before one edate, and end at the 5th row after the same edate. And yes I have many different ric to care about at the same time. Can anyone help please? Thank you.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data WORK.HAVE;&lt;BR /&gt;infile datalines dsd truncover;&lt;BR /&gt;input RIC:$6. Date:DATE11. edate:DATE11. ar:32.;&lt;BR /&gt;format Date DATE11. edate DATE11.;&lt;BR /&gt;datalines;&lt;BR /&gt;AAM.HM 14-APR-2011 . -0.002572834&lt;BR /&gt;AAM.HM 15-APR-2011 . -0.00173594&lt;BR /&gt;AAM.HM 18-APR-2011 . -0.004409639&lt;BR /&gt;AAM.HM 19-APR-2011 . 0.0010875573&lt;BR /&gt;AAM.HM 20-APR-2011 . -0.006170841&lt;BR /&gt;AAM.HM 21-APR-2011 21-APR-2011 -0.00456025&lt;BR /&gt;AAM.HM 22-APR-2011 . 0.0003152569&lt;BR /&gt;AAM.HM 25-APR-2011 . 0.0009864579&lt;BR /&gt;AAM.HM 26-APR-2011 . 0.0156740199&lt;BR /&gt;AAM.HM 27-APR-2011 . -0.021580028&lt;BR /&gt;AAM.HM 28-APR-2011 . -0.002922659&lt;BR /&gt;AAM.HM 15-JUL-2011 . -0.001935623&lt;BR /&gt;AAM.HM 18-JUL-2011 . -0.026651755&lt;BR /&gt;AAM.HM 19-JUL-2011 . 0.0351227743&lt;BR /&gt;AAM.HM 20-JUL-2011 . -0.005652773&lt;BR /&gt;AAM.HM 21-JUL-2011 . 0.0205199523&lt;BR /&gt;AAM.HM 22-JUL-2011 22-JUL-2011 -0.001763768&lt;BR /&gt;AAM.HM 25-JUL-2011 . 0.0037312991&lt;BR /&gt;AAM.HM 26-JUL-2011 . -0.004845419&lt;BR /&gt;AAM.HM 27-JUL-2011 . 0.0690293458&lt;BR /&gt;AAM.HM 28-JUL-2011 . 0.0049640581&lt;BR /&gt;AAM.HM 29-JUL-2011 . -0.00328081&lt;BR /&gt;AAM.HM 17-OCT-2011 . 0.0101872501&lt;BR /&gt;AAM.HM 18-OCT-2011 . -0.01965987&lt;BR /&gt;AAM.HM 19-OCT-2011 . -0.008891549&lt;BR /&gt;AAM.HM 20-OCT-2011 . -0.003530292&lt;BR /&gt;AAM.HM 21-OCT-2011 . -0.000678125&lt;BR /&gt;AAM.HM 24-OCT-2011 24-OCT-2011 -0.000968388&lt;BR /&gt;AAM.HM 25-OCT-2011 . 0.0004973143&lt;BR /&gt;AAM.HM 26-OCT-2011 . -0.000291778&lt;BR /&gt;AAM.HM 27-OCT-2011 . -0.003253837&lt;BR /&gt;AAM.HM 28-OCT-2011 . -0.000593415&lt;BR /&gt;AAM.HM 31-OCT-2011 . 0.0011569607&lt;BR /&gt;AAM.HM 12-JAN-2012 . -0.002383283&lt;BR /&gt;AAM.HM 13-JAN-2012 . 0.0193886276&lt;BR /&gt;AAM.HM 16-JAN-2012 . 0.0029433443&lt;BR /&gt;AAM.HM 17-JAN-2012 . 0.0299181013&lt;BR /&gt;AAM.HM 18-JAN-2012 . 0.0015236122&lt;BR /&gt;AAM.HM 19-JAN-2012 19-JAN-2012 -0.009540873&lt;BR /&gt;AAM.HM 20-JAN-2012 . 0.0047257709&lt;BR /&gt;AAM.HM 30-JAN-2012 . 0.0393953847&lt;BR /&gt;AAM.HM 31-JAN-2012 . 0.0130199334&lt;BR /&gt;AAM.HM 01-FEB-2012 . -0.030948028&lt;BR /&gt;AAM.HM 02-FEB-2012 . 0.0105212996&lt;BR /&gt;AAM.HM 17-APR-2012 . 0.0122813699&lt;BR /&gt;AAM.HM 18-APR-2012 . 0.0190926121&lt;BR /&gt;AAM.HM 19-APR-2012 . 0.0065156055&lt;BR /&gt;AAM.HM 20-APR-2012 . 0.0019513214&lt;BR /&gt;AAM.HM 23-APR-2012 . -0.000155809&lt;BR /&gt;AAM.HM 24-APR-2012 24-APR-2012 0.0033912888&lt;BR /&gt;;;;;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Dec 2018 04:16:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Cumulative-sum-around-an-event-date-by-group/m-p/523219#M4562</guid>
      <dc:creator>PhuongNguyen</dc:creator>
      <dc:date>2018-12-22T04:16:28Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative sum around an event date by group</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Cumulative-sum-around-an-event-date-by-group/m-p/523233#M4569</link>
      <description>&lt;P&gt;A simple two-step method keeping only the cumulative summed records:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data edates;
set have;
obs = _n_;
if not missing(edate) then output;
keep RIC obs;
rename RIC=targetRIC;
run;

data cumsums;
set edates;
do point = max(obs-5, 0) to min(obs+5, nobs);
    set have point=point nobs=nobs;
    if RIC = targetRIC then do;
        cumSum = sum(cumSum, ar);
        output;
        end;
    end;
drop targetRIC obs;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 22 Dec 2018 06:34:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Cumulative-sum-around-an-event-date-by-group/m-p/523233#M4569</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-12-22T06:34:04Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative sum around an event date by group</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Cumulative-sum-around-an-event-date-by-group/m-p/523235#M4570</link>
      <description>&lt;P&gt;Elegant &amp;amp; exquisite. Very nice!&lt;/P&gt;</description>
      <pubDate>Sat, 22 Dec 2018 06:59:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Cumulative-sum-around-an-event-date-by-group/m-p/523235#M4570</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-22T06:59:11Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative sum around an event date by group</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Cumulative-sum-around-an-event-date-by-group/m-p/523306#M4576</link>
      <description>&lt;P&gt;Beautiful. Thank so much&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 23 Dec 2018 00:30:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Cumulative-sum-around-an-event-date-by-group/m-p/523306#M4576</guid>
      <dc:creator>PhuongNguyen</dc:creator>
      <dc:date>2018-12-23T00:30:33Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative sum around an event date by group</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Cumulative-sum-around-an-event-date-by-group/m-p/523311#M4577</link>
      <description>&lt;P&gt;Hi, me again.&lt;/P&gt;&lt;P&gt;With the same dataset above, I want to count from 1 at the 5th row before one edate up to 11 at the 5th row after the same edate. And then the count will be repeated (1 to 11) if there is another edate. Please help. Thank you.&lt;/P&gt;</description>
      <pubDate>Sun, 23 Dec 2018 02:02:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Cumulative-sum-around-an-event-date-by-group/m-p/523311#M4577</guid>
      <dc:creator>PhuongNguyen</dc:creator>
      <dc:date>2018-12-23T02:02:12Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative sum around an event date by group</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Cumulative-sum-around-an-event-date-by-group/m-p/523319#M4582</link>
      <description>&lt;P&gt;Only one statement to add:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cumsums;
set edates;
do point = max(obs-5, 1) to min(obs+5, nobs);
    set have point=point nobs=nobs;
    if RIC = targetRIC then do;
        cumSum = sum(cumSum, ar);
        row = point - obs + 6;
        output;
        end;
    end;
drop targetRIC obs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note, I also corrected the third statement, because point must be greater than zero.&lt;/P&gt;</description>
      <pubDate>Sun, 23 Dec 2018 07:07:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Cumulative-sum-around-an-event-date-by-group/m-p/523319#M4582</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-12-23T07:07:20Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative sum around an event date by group</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Cumulative-sum-around-an-event-date-by-group/m-p/523330#M4585</link>
      <description>&lt;P&gt;So your sample data has EDATE values every 11 observations.&amp;nbsp; Will your real data be that neat?&lt;/P&gt;
&lt;P&gt;If not what do you want to do when there are overlapping windows?&lt;/P&gt;
&lt;P&gt;If the gap between EDATE values is larger than your window&amp;nbsp;what do you want in the output? No record at all?&amp;nbsp; A record with the cumulative sum missing? or zero?&lt;/P&gt;</description>
      <pubDate>Sun, 23 Dec 2018 16:49:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Cumulative-sum-around-an-event-date-by-group/m-p/523330#M4585</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-12-23T16:49:59Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative sum around an event date by group</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Cumulative-sum-around-an-event-date-by-group/m-p/523333#M4586</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;No, my real data has a larger gap among edates. I did a mid step to extract this dataset out.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt;&amp;nbsp;help me on topic SELECT N ROWS BEFORE AND AFTER AN OBSERVATION. They also care about overlap in this step.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I use my real data&amp;nbsp;I want a missing value in the gap between the two edates. Whatever larger than 11 is not my interest, so it is not very important that what value they have.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks Tom.&lt;/P&gt;</description>
      <pubDate>Sun, 23 Dec 2018 19:14:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Cumulative-sum-around-an-event-date-by-group/m-p/523333#M4586</guid>
      <dc:creator>PhuongNguyen</dc:creator>
      <dc:date>2018-12-23T19:14:45Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative sum around an event date by group</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Cumulative-sum-around-an-event-date-by-group/m-p/523335#M4587</link>
      <description>&lt;P&gt;Many thanks to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 23 Dec 2018 19:26:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Cumulative-sum-around-an-event-date-by-group/m-p/523335#M4587</guid>
      <dc:creator>PhuongNguyen</dc:creator>
      <dc:date>2018-12-23T19:26:53Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative sum around an event date by group</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Cumulative-sum-around-an-event-date-by-group/m-p/523339#M4591</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Yes, me with the dataset again.&lt;/P&gt;&lt;P&gt;I am trying to put in groups whenever del_eps has a value and del_eps&amp;lt;0 or del_eps&amp;gt;0. When del_eps's value &amp;gt;0, I want to put them (5 rows before and 5 rows after the del_eps) in group 'A', and group 'B' is for del_eps's value &amp;lt;0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I try to add two more rows into the original codes from yours,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if del_eps&amp;gt;0 then gr='A';&lt;BR /&gt;if del_eps^='.' and del_eps&amp;lt;0 then gr='B';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but they only work&amp;nbsp;from&amp;nbsp;row 6 to row 11, and a blank from row 1 to row 5. Please help again. Thank you so much.&lt;/P&gt;</description>
      <pubDate>Sun, 23 Dec 2018 22:15:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Cumulative-sum-around-an-event-date-by-group/m-p/523339#M4591</guid>
      <dc:creator>PhuongNguyen</dc:creator>
      <dc:date>2018-12-23T22:15:20Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative sum around an event date by group</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Cumulative-sum-around-an-event-date-by-group/m-p/523582#M4657</link>
      <description>&lt;P&gt;Well, I got it. I will call the positive del_eps out to be the targetdel_eps in the 1st step, and do the same with negative del_eps. Solved &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Dec 2018 20:41:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Cumulative-sum-around-an-event-date-by-group/m-p/523582#M4657</guid>
      <dc:creator>PhuongNguyen</dc:creator>
      <dc:date>2018-12-26T20:41:40Z</dc:date>
    </item>
  </channel>
</rss>

