<?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 Counting number of observations within date range by variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-observations-within-date-range-by-variable/m-p/446734#M283282</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a data set such as the following, with date format YYMMDD10:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;ID         Date            Count -5 days&lt;BR /&gt;
004        01/11/2016      0
007        2011/03/10      0
007        2012/12/04      0
007        2012/12/05      1
007        2012/12/05      2
007        2012/12/07      3
008        2012/10/01      0
008        2012/10/04      1
010        2014/11/25      0
010        2015/04/19      0
010        2015/04/20      1&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to count how many times the ID variable occurs within -5 days, or potentially +/-5 days.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be really appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Mon, 19 Mar 2018 12:03:39 GMT</pubDate>
    <dc:creator>Jerram</dc:creator>
    <dc:date>2018-03-19T12:03:39Z</dc:date>
    <item>
      <title>Counting number of observations within date range by variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-observations-within-date-range-by-variable/m-p/446734#M283282</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a data set such as the following, with date format YYMMDD10:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;ID         Date            Count -5 days&lt;BR /&gt;
004        01/11/2016      0
007        2011/03/10      0
007        2012/12/04      0
007        2012/12/05      1
007        2012/12/05      2
007        2012/12/07      3
008        2012/10/01      0
008        2012/10/04      1
010        2014/11/25      0
010        2015/04/19      0
010        2015/04/20      1&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to count how many times the ID variable occurs within -5 days, or potentially +/-5 days.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be really appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 12:03:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-observations-within-date-range-by-variable/m-p/446734#M283282</guid>
      <dc:creator>Jerram</dc:creator>
      <dc:date>2018-03-19T12:03:39Z</dc:date>
    </item>
    <item>
      <title>Re: Counting number of observations within date range by variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-observations-within-date-range-by-variable/m-p/446754#M283283</link>
      <description>&lt;P&gt;A basic SQL solution looks like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id date :yymmdd10.;
format date yymmdd10.;
cards;
004        2016/01/11
007        2011/03/10
007        2012/12/04
007        2012/12/05
007        2012/12/05
007        2012/12/07
008        2012/10/01
008        2012/10/04
010        2014/11/25
010        2015/04/19
010        2015/04/20
;
run;

proc sql;
create table want as
select
  a.id,
  a.date,
  (select count(*) from have b where a.id = b.id and 0 &amp;lt;= a.date - b.date &amp;lt;= 5) -1 as count
from have a
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but it delivers a different count for the first of the double dates.&lt;/P&gt;
&lt;P&gt;Note how I presented your example data in a data step, so that others can easily recreate the dataset.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 12:52:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-observations-within-date-range-by-variable/m-p/446754#M283283</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-19T12:52:57Z</dc:date>
    </item>
    <item>
      <title>Re: Counting number of observations within date range by variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-observations-within-date-range-by-variable/m-p/446854#M283285</link>
      <description>&lt;P&gt;If your requirement is to NOT count the same date you need to explicitly include that in your requirement. Otherwise the same date will count as it is within 5 (or 7 or whatever ) since 0 is in pretty much all -i to +i intervals.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 16:34:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-number-of-observations-within-date-range-by-variable/m-p/446854#M283285</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-03-19T16:34:58Z</dc:date>
    </item>
  </channel>
</rss>

