<?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: Counting consecutively-dated observations of a Yes value with attribution and summing to a varia in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Counting-consecutively-dated-observations-of-a-Yes-value-with/m-p/701229#M214705</link>
    <description>This is an elegant solution, thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;!&lt;BR /&gt;For my growth, I was wondering if you have any good references for what is happening in the data _null_ step with the hash stuff. That seems powerful but I don't follow it - and don't recognize the concepts.</description>
    <pubDate>Tue, 24 Nov 2020 14:48:44 GMT</pubDate>
    <dc:creator>Rodcjones</dc:creator>
    <dc:date>2020-11-24T14:48:44Z</dc:date>
    <item>
      <title>Counting consecutively-dated observations of a Yes value with attribution and summing to a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-consecutively-dated-observations-of-a-Yes-value-with/m-p/699997#M214171</link>
      <description>&lt;P&gt;This question is a new twist on a previous post that was impressively solved by&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/226241"&gt;@AMSAS&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt; at&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Counting-consecutively-dated-observations-of-Yes-value-as-1/m-p/696575#M212794" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Counting-consecutively-dated-observations-of-Yes-value-as-1/m-p/696575#M212794&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The new scenario I'm tackling is how to perform the same counting method by ID but then 1) attribute the count to a new variable and 2) sum by that variable. In the have and want datasets below I seek to count consecutively-dated Yes values, restart the count after 5 ... and use the LOCATION of the first Yes in the run for summing, even when the location changes at some point in the run.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;input date :mmddyy8. id $ event $ location $;&lt;BR /&gt;format date MMDDYY8. ;&lt;BR /&gt;datalines;&lt;BR /&gt;09/01/20 1 Yes A &lt;BR /&gt;09/02/20 1 No A&lt;BR /&gt;09/03/20 1 Yes A&lt;BR /&gt;09/04/20 1 No A&lt;BR /&gt;09/05/20 1 Yes B&lt;BR /&gt;09/06/20 1 No B&lt;BR /&gt;09/07/20 1 Yes B&lt;BR /&gt;09/08/20 1 No B&lt;BR /&gt;09/09/20 1 Yes B&lt;BR /&gt;09/10/20 1 Yes B&lt;BR /&gt;09/11/20 1 Yes C&lt;BR /&gt;09/12/20 1 No C&lt;BR /&gt;09/13/20 1 Yes C&lt;BR /&gt;09/14/20 1 No C&lt;BR /&gt;09/15/20 1 No C&lt;BR /&gt;09/16/20 1 Yes C&lt;BR /&gt;09/17/20 1 No C&lt;BR /&gt;09/18/20 1 No C&lt;BR /&gt;09/19/20 1 No C&lt;BR /&gt;09/20/20 1 Yes C&lt;BR /&gt;09/21/20 1 Yes C&lt;BR /&gt;09/22/20 1 No C&lt;BR /&gt;09/23/20 1 No C&lt;BR /&gt;09/24/20 1 No C&lt;BR /&gt;09/25/20 1 No C&lt;BR /&gt;09/26/20 1 No C&lt;BR /&gt;09/27/20 1 No C&lt;BR /&gt;09/28/20 1 Yes C&lt;BR /&gt;09/29/20 1 No C&lt;BR /&gt;09/30/20 1 No C&lt;BR /&gt;10/01/20 1 No C&lt;BR /&gt;10/02/20 1 No C&lt;BR /&gt;10/03/20 1 No C&lt;BR /&gt;10/04/20 1 No C&lt;BR /&gt;10/05/20 1 Yes Z&lt;BR /&gt;10/06/20 1 No Z&lt;BR /&gt;10/07/20 1 No Z&lt;BR /&gt;10/08/20 1 No Z&lt;BR /&gt;10/09/20 1 Yes Z&lt;BR /&gt;10/10/20 1 No Z&lt;BR /&gt;10/11/20 1 No Z&lt;BR /&gt;10/12/20 1 No Z&lt;BR /&gt;10/13/20 1 No Z&lt;BR /&gt;10/14/20 1 No D&lt;BR /&gt;09/01/20 2 No A&lt;BR /&gt;09/02/20 2 No A&lt;BR /&gt;09/03/20 2 No A&lt;BR /&gt;09/04/20 2 Yes A&lt;BR /&gt;09/05/20 2 Yes A&lt;BR /&gt;09/06/20 2 Yes E&lt;BR /&gt;09/07/20 2 Yes E&lt;BR /&gt;09/08/20 2 Yes E&lt;BR /&gt;09/09/20 2 Yes B&lt;BR /&gt;09/10/20 2 Yes B&lt;BR /&gt;09/11/20 2 Yes B&lt;BR /&gt;09/12/20 2 Yes B&lt;BR /&gt;09/13/20 2 Yes B&lt;BR /&gt;09/14/20 2 Yes B&lt;BR /&gt;09/15/20 2 Yes B&lt;BR /&gt;09/16/20 2 Yes B&lt;BR /&gt;09/17/20 2 No B&lt;/P&gt;
&lt;P&gt;;&lt;BR /&gt;run ;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;input LOCATION $ sum ;&lt;BR /&gt;datalines;&lt;BR /&gt;A 3&lt;BR /&gt;B 5&lt;BR /&gt;C 4&lt;BR /&gt;Z 2&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Nov 2020 21:22:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-consecutively-dated-observations-of-a-Yes-value-with/m-p/699997#M214171</guid>
      <dc:creator>Rodcjones</dc:creator>
      <dc:date>2020-11-18T21:22:02Z</dc:date>
    </item>
    <item>
      <title>Re: Counting consecutively-dated observations of a Yes value with attribution and summing to a varia</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-consecutively-dated-observations-of-a-Yes-value-with/m-p/699999#M214172</link>
      <description>&lt;P&gt;So walk me through this: Why is sum=3 at location='A' ?&lt;/P&gt;</description>
      <pubDate>Wed, 18 Nov 2020 21:29:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-consecutively-dated-observations-of-a-Yes-value-with/m-p/699999#M214172</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-11-18T21:29:14Z</dc:date>
    </item>
    <item>
      <title>Re: Counting consecutively-dated observations of a Yes value with attribution and summing to a varia</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-consecutively-dated-observations-of-a-Yes-value-with/m-p/700002#M214175</link>
      <description>Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt; ,&lt;BR /&gt;Location A's total comes from these records:&lt;BR /&gt;09/01/20 1 Yes A&lt;BR /&gt;+&lt;BR /&gt;09/03/20 1 Yes A&lt;BR /&gt;+&lt;BR /&gt;09/04/20 2 Yes A&lt;BR /&gt;09/05/20 2 Yes A&lt;BR /&gt;09/06/20 2 Yes E&lt;BR /&gt;09/07/20 2 Yes E&lt;BR /&gt;09/08/20 2 Yes E&lt;BR /&gt;&lt;BR /&gt;This last group of 5 is counted as 1 (see link to prior post for more on that).</description>
      <pubDate>Wed, 18 Nov 2020 21:32:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-consecutively-dated-observations-of-a-Yes-value-with/m-p/700002#M214175</guid>
      <dc:creator>Rodcjones</dc:creator>
      <dc:date>2020-11-18T21:32:58Z</dc:date>
    </item>
    <item>
      <title>Re: Counting consecutively-dated observations of a Yes value with attribution and summing to a varia</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-consecutively-dated-observations-of-a-Yes-value-with/m-p/700006#M214177</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/33790"&gt;@Rodcjones&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt; ,&lt;BR /&gt;Location A's total comes from these records:&lt;BR /&gt;09/01/20 1 Yes A&lt;BR /&gt;+&lt;BR /&gt;09/03/20 1 Yes A&lt;BR /&gt;+&lt;BR /&gt;09/04/20 2 Yes A&lt;BR /&gt;09/05/20 2 Yes A&lt;BR /&gt;09/06/20 2 Yes E&lt;BR /&gt;09/07/20 2 Yes E&lt;BR /&gt;09/08/20 2 Yes E&lt;BR /&gt;&lt;BR /&gt;This last group of 5 is counted as 1 (see link to prior post for more on that).&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That is NOT consecutive date with Yes, the 09/02/20 is NOT a Yes.&lt;/P&gt;
&lt;P&gt;So it appears that you need to define "consecutive" in a bit more detail in relation to this data.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Nov 2020 21:53:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-consecutively-dated-observations-of-a-Yes-value-with/m-p/700006#M214177</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-11-18T21:53:24Z</dc:date>
    </item>
    <item>
      <title>Re: Counting consecutively-dated observations of a Yes value with attribution and summing to a varia</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-consecutively-dated-observations-of-a-Yes-value-with/m-p/700015#M214181</link>
      <description>The counting rule I needed to implement says to count consecutively-dated observations of a Yes value as 1 until 5 in a row or a No value, then start over. This counting is done at the ID level. In the case of ID 1 it's correct that the No value on 9/2 interrupts the string of Yes's, and counting restarts at the next Yes  for ID 1, which is on 9/3.</description>
      <pubDate>Wed, 18 Nov 2020 22:26:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-consecutively-dated-observations-of-a-Yes-value-with/m-p/700015#M214181</guid>
      <dc:creator>Rodcjones</dc:creator>
      <dc:date>2020-11-18T22:26:26Z</dc:date>
    </item>
    <item>
      <title>Re: Counting consecutively-dated observations of a Yes value with attribution and summing to a varia</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-consecutively-dated-observations-of-a-Yes-value-with/m-p/700038#M214198</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/33790"&gt;@Rodcjones&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;The counting rule I needed to implement says to count consecutively-dated observations of a Yes value as 1 until 5 in a row or a No value, then start over. This counting is done at the ID level. In the case of ID 1 it's correct that the No value on 9/2 interrupts the string of Yes's, and counting restarts at the next Yes for ID 1, which is on 9/3.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So your posted want is incorrect:&lt;/P&gt;
&lt;PRE&gt;data want;
input LOCATION $ sum ;
datalines;
A 3
B 5
C 4
Z 2&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Nov 2020 23:09:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-consecutively-dated-observations-of-a-Yes-value-with/m-p/700038#M214198</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-11-18T23:09:10Z</dc:date>
    </item>
    <item>
      <title>Re: Counting consecutively-dated observations of a Yes value with attribution and summing to a varia</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-consecutively-dated-observations-of-a-Yes-value-with/m-p/700065#M214210</link>
      <description>&lt;P&gt;Shouldn't C have a count of 5?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;---- 10 Lines Not Displayed ----&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;09/11/20 1 Yes C&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;---- 1 Line Not Displayed ----&lt;BR /&gt;09/13/20 1 Yes C&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;---- 2 Lines Not Displayed ----&lt;BR /&gt;09/16/20 1 Yes C&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;---- 3 Lines Not Displayed ----&lt;BR /&gt;09/20/20 1 Yes C&lt;BR /&gt;09/21/20 1 Yes C&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;---- 6 Lines Not Displayed ----&lt;BR /&gt;09/28/20 1 Yes C&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;---- 33 Lines Not Displayed ----&lt;/FONT&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Assuming your answer is Yes, then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input date :mmddyy8. id $ event $ location $;
format date MMDDYY8. ;
datalines;
09/01/20 1 Yes A
09/02/20 1 No A
09/03/20 1 Yes A
09/04/20 1 No A
09/05/20 1 Yes B
09/06/20 1 No B
09/07/20 1 Yes B
09/08/20 1 No B
09/09/20 1 Yes B
09/10/20 1 Yes B
09/11/20 1 Yes C
09/12/20 1 No C
09/13/20 1 Yes C
09/14/20 1 No C
09/15/20 1 No C
09/16/20 1 Yes C
09/17/20 1 No C
09/18/20 1 No C
09/19/20 1 No C
09/20/20 1 Yes C
09/21/20 1 Yes C
09/22/20 1 No C
09/23/20 1 No C
09/24/20 1 No C
09/25/20 1 No C
09/26/20 1 No C
09/27/20 1 No C
09/28/20 1 Yes C
09/29/20 1 No C
09/30/20 1 No C
10/01/20 1 No C
10/02/20 1 No C
10/03/20 1 No C
10/04/20 1 No C
10/05/20 1 Yes Z
10/06/20 1 No Z
10/07/20 1 No Z
10/08/20 1 No Z
10/09/20 1 Yes Z
10/10/20 1 No Z
10/11/20 1 No Z
10/12/20 1 No Z
10/13/20 1 No Z
10/14/20 1 No D
09/01/20 2 No A
09/02/20 2 No A
09/03/20 2 No A
09/04/20 2 Yes A
09/05/20 2 Yes A
09/06/20 2 Yes E
09/07/20 2 Yes E
09/08/20 2 Yes E
09/09/20 2 Yes B
09/10/20 2 Yes B
09/11/20 2 Yes B
09/12/20 2 Yes B
09/13/20 2 Yes B
09/14/20 2 Yes B
09/15/20 2 Yes B
09/16/20 2 Yes B
09/17/20 2 No B
run ;

data _null_;
  if 0 then set have;
  if _n_=1 then do;
    call missing(sum);
    declare hash h (ordered:'A');
	  h.definekey('location');
	  h.definedata('location','sum');
	  h.definedone();
  end;

  do _n=1 to 5 until (last.event);
    set have end=end_of_have;
	by location event notsorted;
  end;

  if event='Yes' then do;
    if h.find()^=0 then sum=1;
	else sum+1;
	h.replace();
  end;
  if end_of_have then h.output(dataset:'want');

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Nov 2020 01:22:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-consecutively-dated-observations-of-a-Yes-value-with/m-p/700065#M214210</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-11-19T01:22:52Z</dc:date>
    </item>
    <item>
      <title>Re: Counting consecutively-dated observations of a Yes value with attribution and summing to a varia</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-consecutively-dated-observations-of-a-Yes-value-with/m-p/700996#M214605</link>
      <description>&lt;P&gt;C doesn't have a sum of 5 because this row&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;09/21/20 1 Yes C&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;is part of a consecutive run. Once the run has gone 5 days for the same ID, the count should reset, but since this is only the 2nd day of Yes for ID 1, it is associated with the preceding record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I inadvertently seem to have come up with an example and scenario that's tough to follow, so I appreciate the patience and assistance. In this HAVE dataset below I gave a value of 1 to the count_it variable for rows that should be counted. Hopefully that might explain how I came up with the sums in WANT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;input date :mmddyy8. id $ event $ location $ count_it;&lt;BR /&gt;format date MMDDYY8. ;&lt;BR /&gt;datalines; &lt;BR /&gt;09/01/20 1 Yes A 1&lt;BR /&gt;09/02/20 1 No A 0&lt;BR /&gt;09/03/20 1 Yes A 1&lt;BR /&gt;09/04/20 1 No A 0&lt;BR /&gt;09/05/20 1 Yes B 1&lt;BR /&gt;09/06/20 1 No B 0&lt;BR /&gt;09/07/20 1 Yes B 1&lt;BR /&gt;09/08/20 1 No B 0&lt;BR /&gt;09/09/20 1 Yes B 1&lt;BR /&gt;09/10/20 1 Yes B 0&lt;BR /&gt;09/11/20 1 Yes C 0&lt;BR /&gt;09/12/20 1 No C 0&lt;BR /&gt;09/13/20 1 Yes C 1&lt;BR /&gt;09/14/20 1 No C 0&lt;BR /&gt;09/15/20 1 No C 0&lt;BR /&gt;09/16/20 1 Yes C 1&lt;BR /&gt;09/17/20 1 No C 0&lt;BR /&gt;09/18/20 1 No C 0&lt;BR /&gt;09/19/20 1 No C 0&lt;BR /&gt;09/20/20 1 Yes C 1&lt;BR /&gt;09/21/20 1 Yes C 0&lt;BR /&gt;09/22/20 1 No C 0&lt;BR /&gt;09/23/20 1 No C 0&lt;BR /&gt;09/24/20 1 No C 0&lt;BR /&gt;09/25/20 1 No C 0&lt;BR /&gt;09/26/20 1 No C 0&lt;BR /&gt;09/27/20 1 No C 0&lt;BR /&gt;09/28/20 1 Yes C 1&lt;BR /&gt;09/29/20 1 No C 0&lt;BR /&gt;09/30/20 1 No C 0&lt;BR /&gt;10/01/20 1 No C 0&lt;BR /&gt;10/02/20 1 No C 0&lt;BR /&gt;10/03/20 1 No C 0&lt;BR /&gt;10/04/20 1 No C 0&lt;BR /&gt;10/05/20 1 Yes Z 1 &lt;BR /&gt;10/06/20 1 No Z 0&lt;BR /&gt;10/07/20 1 No Z 0&lt;BR /&gt;10/08/20 1 No Z 0&lt;BR /&gt;10/09/20 1 Yes Z 1&lt;BR /&gt;10/10/20 1 No Z 0&lt;BR /&gt;10/11/20 1 No Z 0&lt;BR /&gt;10/12/20 1 No Z 0&lt;BR /&gt;10/13/20 1 No Z 0&lt;BR /&gt;10/14/20 1 No D 0&lt;BR /&gt;09/01/20 2 No A 0&lt;BR /&gt;09/02/20 2 No A 0&lt;BR /&gt;09/03/20 2 No A 0&lt;BR /&gt;09/04/20 2 Yes A 1&lt;BR /&gt;09/05/20 2 Yes A 0&lt;BR /&gt;09/06/20 2 Yes E 0&lt;BR /&gt;09/07/20 2 Yes E 0&lt;BR /&gt;09/08/20 2 Yes E 0&lt;BR /&gt;09/09/20 2 Yes B 1&lt;BR /&gt;09/10/20 2 Yes B 0&lt;BR /&gt;09/11/20 2 Yes B 0&lt;BR /&gt;09/12/20 2 Yes B 0&lt;BR /&gt;09/13/20 2 Yes B 0&lt;BR /&gt;09/14/20 2 Yes B 1&lt;BR /&gt;09/15/20 2 Yes B 0&lt;BR /&gt;09/16/20 2 Yes B 0&lt;BR /&gt;09/17/20 2 No B 0&lt;BR /&gt;;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Nov 2020 18:13:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-consecutively-dated-observations-of-a-Yes-value-with/m-p/700996#M214605</guid>
      <dc:creator>Rodcjones</dc:creator>
      <dc:date>2020-11-23T18:13:30Z</dc:date>
    </item>
    <item>
      <title>Re: Counting consecutively-dated observations of a Yes value with attribution and summing to a varia</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-consecutively-dated-observations-of-a-Yes-value-with/m-p/701139#M214678</link>
      <description>&lt;P&gt;OK, I get it now.&amp;nbsp; This program uses your original data and matches your WANT dataset:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input date :mmddyy8. id $ event $ location $;
  format date MMDDYY8. ;
datalines;
09/01/20 1 Yes A
09/02/20 1 No A
09/03/20 1 Yes A
09/04/20 1 No A
09/05/20 1 Yes B
09/06/20 1 No B
09/07/20 1 Yes B
09/08/20 1 No B
09/09/20 1 Yes B
09/10/20 1 Yes B
09/11/20 1 Yes C
09/12/20 1 No C
09/13/20 1 Yes C
09/14/20 1 No C
09/15/20 1 No C
09/16/20 1 Yes C
09/17/20 1 No C
09/18/20 1 No C
09/19/20 1 No C
09/20/20 1 Yes C
09/21/20 1 Yes C
09/22/20 1 No C
09/23/20 1 No C
09/24/20 1 No C
09/25/20 1 No C
09/26/20 1 No C
09/27/20 1 No C
09/28/20 1 Yes C
09/29/20 1 No C
09/30/20 1 No C
10/01/20 1 No C
10/02/20 1 No C
10/03/20 1 No C
10/04/20 1 No C
10/05/20 1 Yes Z
10/06/20 1 No Z
10/07/20 1 No Z
10/08/20 1 No Z
10/09/20 1 Yes Z
10/10/20 1 No Z
10/11/20 1 No Z
10/12/20 1 No Z
10/13/20 1 No Z
10/14/20 1 No D
09/01/20 2 No A
09/02/20 2 No A
09/03/20 2 No A
09/04/20 2 Yes A
09/05/20 2 Yes A
09/06/20 2 Yes E
09/07/20 2 Yes E
09/08/20 2 Yes E
09/09/20 2 Yes B
09/10/20 2 Yes B
09/11/20 2 Yes B
09/12/20 2 Yes B
09/13/20 2 Yes B
09/14/20 2 Yes B
09/15/20 2 Yes B
09/16/20 2 Yes B
09/17/20 2 No B
run ;

data _null_;
  set have (where=(event='Yes')) end=end_of_have;
  by id;
  if _n_=1 then do;
    declare hash h (ordered:'a');
	  h.definekey('location');
	  h.definedata('location','sum');
	  h.definedone();
  end;

  if first.id=1 or lag(date)^=date-1 then date_sequence=1;
  else date_sequence+1;
  if mod(date_sequence,5)=1 then do;
    if h.find()^=0 then sum=1;
	else sum=sum+1;
	h.replace();
  end;

  if end_of_have;
  h.output(dataset:'want');
run;

proc print data=want;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Nov 2020 05:06:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-consecutively-dated-observations-of-a-Yes-value-with/m-p/701139#M214678</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-11-24T05:06:05Z</dc:date>
    </item>
    <item>
      <title>Re: Counting consecutively-dated observations of a Yes value with attribution and summing to a varia</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-consecutively-dated-observations-of-a-Yes-value-with/m-p/701229#M214705</link>
      <description>This is an elegant solution, thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;!&lt;BR /&gt;For my growth, I was wondering if you have any good references for what is happening in the data _null_ step with the hash stuff. That seems powerful but I don't follow it - and don't recognize the concepts.</description>
      <pubDate>Tue, 24 Nov 2020 14:48:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-consecutively-dated-observations-of-a-Yes-value-with/m-p/701229#M214705</guid>
      <dc:creator>Rodcjones</dc:creator>
      <dc:date>2020-11-24T14:48:44Z</dc:date>
    </item>
  </channel>
</rss>

