<?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: how to add values within a certain date difference for each date? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-add-values-within-a-certain-date-difference-for-each-date/m-p/761610#M241020</link>
    <description>&lt;P&gt;How about using PROC SQL to join the table with itself?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input id date1 :yymmdd10. dose;
	format date1 yymmdd10. ;
cards;
1 20010927 10
1 20011003 20
1 20020204 100
2 20010314 10
2 20010426 50
2 20010509 25
;

proc sql;
create table want as
  select a.id, a.date1, a.dose
       , sum(b.dose) as total
  from have a 
    inner join have b
    on a.id = b.id 
      and b.date1 between a.date1 and a.date1+90
  group by a.id,a.date1,a.dose
  order by id,date1
;
quit;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    id         date1    dose    total

 1      1    2001-09-27      10      30
 2      1    2001-10-03      20      20
 3      1    2002-02-04     100     100
 4      2    2001-03-14      10      85
 5      2    2001-04-26      50      75
 6      2    2001-05-09      25      25
&lt;/PRE&gt;</description>
    <pubDate>Sat, 14 Aug 2021 21:01:11 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-08-14T21:01:11Z</dc:date>
    <item>
      <title>how to add values within a certain date difference for each date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-add-values-within-a-certain-date-difference-for-each-date/m-p/761604#M241018</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;hi!&lt;/P&gt;
&lt;P&gt;i&amp;nbsp;want to create a variable dose_90 by adding the doses of each row within 90 days from each Index_Date by ID.&lt;/P&gt;
&lt;P&gt;For example, when Index_Date is September 27, 2001 as shown in the figure below, among other index_dates of the ID, the dose( 20mg) is added to 10mg of the existing row to yield 30mg.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input id date1 :yymmdd10. dose;
	format date1 yymmdd10. ;
cards;
1 20010927 10
1 20011003 20
1 20020204 100
2 20010314 10
2 20010426 50
2 20010509 25
;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 15 Aug 2021 00:28:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-add-values-within-a-certain-date-difference-for-each-date/m-p/761604#M241018</guid>
      <dc:creator>AmeeKang</dc:creator>
      <dc:date>2021-08-15T00:28:22Z</dc:date>
    </item>
    <item>
      <title>Re: how to add values within a certain date difference for each date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-add-values-within-a-certain-date-difference-for-each-date/m-p/761610#M241020</link>
      <description>&lt;P&gt;How about using PROC SQL to join the table with itself?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input id date1 :yymmdd10. dose;
	format date1 yymmdd10. ;
cards;
1 20010927 10
1 20011003 20
1 20020204 100
2 20010314 10
2 20010426 50
2 20010509 25
;

proc sql;
create table want as
  select a.id, a.date1, a.dose
       , sum(b.dose) as total
  from have a 
    inner join have b
    on a.id = b.id 
      and b.date1 between a.date1 and a.date1+90
  group by a.id,a.date1,a.dose
  order by id,date1
;
quit;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    id         date1    dose    total

 1      1    2001-09-27      10      30
 2      1    2001-10-03      20      20
 3      1    2002-02-04     100     100
 4      2    2001-03-14      10      85
 5      2    2001-04-26      50      75
 6      2    2001-05-09      25      25
&lt;/PRE&gt;</description>
      <pubDate>Sat, 14 Aug 2021 21:01:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-add-values-within-a-certain-date-difference-for-each-date/m-p/761610#M241020</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-08-14T21:01:11Z</dc:date>
    </item>
  </channel>
</rss>

