<?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 Summ values between two dates for each rown within a group in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Summ-values-between-two-dates-for-each-rown-within-a-group/m-p/664275#M198414</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have following dataset&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data have;
infile datalines missover; 
   input lag24 mmddyy10. id date  mmddyy10. score;
   format date mmddyy10.;
   format lag24 mmddyy10.;
   datalines; 
           1 21-09-2009 1.4   
25-09-2007 1 25-09-2009 1.4
16-11-2007 1 16-11-2009 2.2
03-02-2008 1 03-02-2010 2.6
           2 21-09-2009 1.4   
25-09-2007 2 25-09-2009 1.4
16-11-2007 2 16-11-2009 2.2
03-02-2008 2 03-02-2010 2.6
;       
run;&lt;/PRE&gt;&lt;P&gt;I need the following data. We start with the last row within the group variable "ID", and check if the previous dates are&amp;nbsp;within two years of the last date. Lets say the last date in the ID=1 is&amp;nbsp;03-02-2010 and the previous date is&amp;nbsp;16-11-2009 which is between&amp;nbsp;03-02-2008 and&amp;nbsp;03-02-2010, so take we sum of score (2.6+2.2). Then again check if the date before the previous date, ie. 2nd row from top&amp;nbsp;25-09-2009 is between&amp;nbsp;03-02-2008 and&amp;nbsp;03-02-2010,&amp;nbsp;so take we sum of score (2.6+2.2+1.4) and again for the first row&amp;nbsp;(2.6+2.2+1.41.4=7.6) which is diplayed on the last row. Similarly we take the 2nd last row as "index row" and check if the previous dates are between the date of index date and lag24=(index date-24 months).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data want;
infile datalines missover; 
   input lag24 mmddyy10. id date  mmddyy10. score sum;
   format date mmddyy10.;
   format lag24 mmddyy10.;
   datalines; 
           1 21-09-2009 1.4 
25-09-2007 1 25-09-2009 1.4 2.8
16-11-2007 1 16-11-2009 2.2 6.2
03-02-2008 1 03-02-2010 2.6 7.6
           2 21-09-2009 1.4   
25-09-2007 2 25-09-2009 1.4 2.8
16-11-2007 2 16-11-2009 2.2 5
03-02-2012 2 03-02-2014 2.6
;       
run;&lt;/PRE&gt;</description>
    <pubDate>Tue, 23 Jun 2020 13:29:15 GMT</pubDate>
    <dc:creator>ifti_ch2002</dc:creator>
    <dc:date>2020-06-23T13:29:15Z</dc:date>
    <item>
      <title>Summ values between two dates for each rown within a group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summ-values-between-two-dates-for-each-rown-within-a-group/m-p/664275#M198414</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have following dataset&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data have;
infile datalines missover; 
   input lag24 mmddyy10. id date  mmddyy10. score;
   format date mmddyy10.;
   format lag24 mmddyy10.;
   datalines; 
           1 21-09-2009 1.4   
25-09-2007 1 25-09-2009 1.4
16-11-2007 1 16-11-2009 2.2
03-02-2008 1 03-02-2010 2.6
           2 21-09-2009 1.4   
25-09-2007 2 25-09-2009 1.4
16-11-2007 2 16-11-2009 2.2
03-02-2008 2 03-02-2010 2.6
;       
run;&lt;/PRE&gt;&lt;P&gt;I need the following data. We start with the last row within the group variable "ID", and check if the previous dates are&amp;nbsp;within two years of the last date. Lets say the last date in the ID=1 is&amp;nbsp;03-02-2010 and the previous date is&amp;nbsp;16-11-2009 which is between&amp;nbsp;03-02-2008 and&amp;nbsp;03-02-2010, so take we sum of score (2.6+2.2). Then again check if the date before the previous date, ie. 2nd row from top&amp;nbsp;25-09-2009 is between&amp;nbsp;03-02-2008 and&amp;nbsp;03-02-2010,&amp;nbsp;so take we sum of score (2.6+2.2+1.4) and again for the first row&amp;nbsp;(2.6+2.2+1.41.4=7.6) which is diplayed on the last row. Similarly we take the 2nd last row as "index row" and check if the previous dates are between the date of index date and lag24=(index date-24 months).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data want;
infile datalines missover; 
   input lag24 mmddyy10. id date  mmddyy10. score sum;
   format date mmddyy10.;
   format lag24 mmddyy10.;
   datalines; 
           1 21-09-2009 1.4 
25-09-2007 1 25-09-2009 1.4 2.8
16-11-2007 1 16-11-2009 2.2 6.2
03-02-2008 1 03-02-2010 2.6 7.6
           2 21-09-2009 1.4   
25-09-2007 2 25-09-2009 1.4 2.8
16-11-2007 2 16-11-2009 2.2 5
03-02-2012 2 03-02-2014 2.6
;       
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Jun 2020 13:29:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summ-values-between-two-dates-for-each-rown-within-a-group/m-p/664275#M198414</guid>
      <dc:creator>ifti_ch2002</dc:creator>
      <dc:date>2020-06-23T13:29:15Z</dc:date>
    </item>
    <item>
      <title>Re: Summ values between two dates for each rown within a group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summ-values-between-two-dates-for-each-rown-within-a-group/m-p/664277#M198416</link>
      <description>&lt;P&gt;One mistake. Date in Last row of data "have" is same as in data "want"&lt;/P&gt;&lt;PRE&gt;data have;
infile datalines missover; 
   input lag24 mmddyy10. id date  mmddyy10. score;
   format date mmddyy10.;
   format lag24 mmddyy10.;
   datalines; 
           1 21-09-2009 1.4   
25-09-2007 1 25-09-2009 1.4
16-11-2007 1 16-11-2009 2.2
03-02-2008 1 03-02-2010 2.6
           2 21-09-2009 1.4   
25-09-2007 2 25-09-2009 1.4
16-11-2007 2 16-11-2009 2.2
03-02-2012 2 03-02-2014 2.6
;       
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Jun 2020 13:31:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summ-values-between-two-dates-for-each-rown-within-a-group/m-p/664277#M198416</guid>
      <dc:creator>ifti_ch2002</dc:creator>
      <dc:date>2020-06-23T13:31:40Z</dc:date>
    </item>
    <item>
      <title>Re: Summ values between two dates for each rown within a group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summ-values-between-two-dates-for-each-rown-within-a-group/m-p/664294#M198426</link>
      <description>&lt;P&gt;Please correct your data step code so that it works and delivers valid data. Your dates are (among other things) in &amp;nbsp;DMY order, so the MMDDYY informat won't work.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jun 2020 14:03:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summ-values-between-two-dates-for-each-rown-within-a-group/m-p/664294#M198426</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-06-23T14:03:57Z</dc:date>
    </item>
    <item>
      <title>Re: Summ values between two dates for each rown within a group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summ-values-between-two-dates-for-each-rown-within-a-group/m-p/664945#M198725</link>
      <description>&lt;P&gt;Sorry for that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;. Please have a look on that&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Summ-values-between-two-dates-for-each-row-within-a-group/m-p/664943#M198724" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Summ-values-between-two-dates-for-each-row-within-a-group/m-p/664943#M198724&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 10:12:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summ-values-between-two-dates-for-each-rown-within-a-group/m-p/664945#M198725</guid>
      <dc:creator>ifti_ch2002</dc:creator>
      <dc:date>2020-06-25T10:12:42Z</dc:date>
    </item>
  </channel>
</rss>

