<?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: SAS9.4 How to sum values over a range of dates? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/SAS9-4-How-to-sum-values-over-a-range-of-dates/m-p/716678#M80125</link>
    <description>&lt;P&gt;I tried the hash approach, too. Works great. Thanks a lot.&lt;/P&gt;</description>
    <pubDate>Wed, 03 Feb 2021 21:44:41 GMT</pubDate>
    <dc:creator>sas112</dc:creator>
    <dc:date>2021-02-03T21:44:41Z</dc:date>
    <item>
      <title>SAS9.4 How to sum values over a range of dates?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS9-4-How-to-sum-values-over-a-range-of-dates/m-p/716048#M80105</link>
      <description>&lt;P&gt;PatientID&amp;nbsp; &amp;nbsp; SvcDate&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; OpCode&amp;nbsp; &amp;nbsp; &amp;nbsp;Pay&lt;BR /&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;BR /&gt;101&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01/13/2013&amp;nbsp; &amp;nbsp; 19&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 30.7&lt;BR /&gt;101&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01/14/2013&amp;nbsp; &amp;nbsp; 12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 11.3&lt;BR /&gt;101&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01/16/2013&amp;nbsp; &amp;nbsp; 13&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 28.0&lt;BR /&gt;101&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01/16/2013&amp;nbsp; &amp;nbsp; 12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 60.2&lt;BR /&gt;101&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;02/09/2013&amp;nbsp; &amp;nbsp; 10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 11.4&lt;BR /&gt;102&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;02/10/2013&amp;nbsp; &amp;nbsp; 12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 9.2&lt;BR /&gt;102&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;02/10/2013&amp;nbsp; &amp;nbsp; 19&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 13.2&lt;BR /&gt;102&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;02/11/2013&amp;nbsp; &amp;nbsp; 13&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 32.1&lt;BR /&gt;102&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;02/12/2013&amp;nbsp; &amp;nbsp; 14&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 17.5&lt;BR /&gt;102&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;02/13/2013&amp;nbsp; &amp;nbsp; 15&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10.2&lt;BR /&gt;102&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;02/19/2013&amp;nbsp; &amp;nbsp; 12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 14.3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello, I am trying to sum up the **Pay** variable for the observations that are 2 days before and 2 days after the observation with **Opcode = 13**. For example, for **PatientID = 101**, the **Opcode = 13** observation falls on **SVCDate = 01/16/2013**, so I would like to sum up all the **Pay** variables for **SVCDate = 01/14/2013 to SVCDate = 01/18/2013**. So this would include the observations for Patient 101 with **Pay** variable equal to 11.3, 28.0, and 60.2. Thus, the operation would be 11.3 + 28.0 + 60.2 = 99.5. I would like to put this 99.5 into a new table that has 2 variables: PatientID and DirectProcedureCost. DirectProcedureCost for Patient 101 would be 99.5.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to loop through all my patient IDs and be able to obtain the DirectProcedureCost for each one. What would be the best way in SAS9.4 to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance for the help!&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2021 12:39:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS9-4-How-to-sum-values-over-a-range-of-dates/m-p/716048#M80105</guid>
      <dc:creator>sas112</dc:creator>
      <dc:date>2021-02-02T12:39:49Z</dc:date>
    </item>
    <item>
      <title>Re: SAS9.4 How to sum values over a range of dates?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS9-4-How-to-sum-values-over-a-range-of-dates/m-p/716051#M80106</link>
      <description>&lt;P&gt;Can optcode be equal to 13 in more than one obs for each PatiendtID?&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2021 12:46:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS9-4-How-to-sum-values-over-a-range-of-dates/m-p/716051#M80106</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-02-02T12:46:33Z</dc:date>
    </item>
    <item>
      <title>Re: SAS9.4 How to sum values over a range of dates?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS9-4-How-to-sum-values-over-a-range-of-dates/m-p/716054#M80107</link>
      <description>&lt;P&gt;With a SQL sub-select:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input PatientID $ SvcDate :mmddyy10. OpCode :$2. Pay;
format svcdate yymmdd10.;
datalines;
101             01/13/2013    19              30.7
101             01/14/2013    12              11.3
101             01/16/2013    13              28.0
101             01/16/2013    12              60.2
101             02/09/2013    10              11.4
102             02/10/2013    12              9.2
102             02/10/2013    19              13.2
102             02/11/2013    13              32.1
102             02/12/2013    14              17.5
102             02/13/2013    15              10.2
102             02/19/2013    12              14.3
;

proc sql;
create table want as
  select a.patientid,
  (
    select sum(pay)
    from have b
    where
      abs(a.svcdate - b.svcdate) le 2 and
      a.patientid = b.patientid
  ) as DirectProcedureCost
  from have a
  where a.opcode = '13'
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note how source data is presented as a data step with datalines; please do so yourself in the future, so we can recreate an exact copy of the dataset with copy/paste and submit.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2021 12:54:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS9-4-How-to-sum-values-over-a-range-of-dates/m-p/716054#M80107</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-02-02T12:54:17Z</dc:date>
    </item>
    <item>
      <title>Re: SAS9.4 How to sum values over a range of dates?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS9-4-How-to-sum-values-over-a-range-of-dates/m-p/716056#M80108</link>
      <description>&lt;P&gt;Here is my approach.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let me know if this works for you and feel free to ask.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input PatientID SvcDate :mmddyy10. OpCode Pay;
format SvcDate mmddyy10.;
datalines;
101 01/13/2013 19 30.7
101 01/14/2013 12 11.3
101 01/16/2013 13 28.0
101 01/16/2013 12 60.2
101 02/09/2013 10 11.4
102 02/10/2013 12 9.2
102 02/10/2013 19 13.2
102 02/11/2013 13 32.1
102 02/12/2013 14 17.5
102 02/13/2013 15 10.2
102 02/19/2013 12 14.3
;

data want;

   if _N_ = 1 then do;
      dcl hash h(dataset : "have", multidata : "Y");
      h.definekey("PatientID", "SvcDate");
      h.definedata("Pay");
      h.definedone();
   end;

   set have;
   where OpCode = 13;

   DirectProcedureCost = 0;

   do dt = SvcDate - 2 to SvcDate + 2;
      do while(h.do_over(key : PatientID, key : dt) = 0);
         DirectProcedureCost + Pay;
      end;
   end;

   keep PatientID DirectProcedureCost;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;PatientID DirectProcedureCost 
101       99.5 
102       82.2 &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2021 12:55:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS9-4-How-to-sum-values-over-a-range-of-dates/m-p/716056#M80108</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-02-02T12:55:59Z</dc:date>
    </item>
    <item>
      <title>Re: SAS9.4 How to sum values over a range of dates?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS9-4-How-to-sum-values-over-a-range-of-dates/m-p/716678#M80125</link>
      <description>&lt;P&gt;I tried the hash approach, too. Works great. Thanks a lot.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 21:44:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS9-4-How-to-sum-values-over-a-range-of-dates/m-p/716678#M80125</guid>
      <dc:creator>sas112</dc:creator>
      <dc:date>2021-02-03T21:44:41Z</dc:date>
    </item>
  </channel>
</rss>

