<?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: Counter Reset After Condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Counter-Reset-After-Condition/m-p/799839#M314556</link>
    <description>&lt;P&gt;Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;.&amp;nbsp;This solution worked great. Yes, I made an error in the datalines for the last two observations for person 1. Thanks again.&lt;/P&gt;</description>
    <pubDate>Thu, 03 Mar 2022 13:44:45 GMT</pubDate>
    <dc:creator>eabc0351</dc:creator>
    <dc:date>2022-03-03T13:44:45Z</dc:date>
    <item>
      <title>Counter Reset After Condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counter-Reset-After-Condition/m-p/799726#M314481</link>
      <description>&lt;P&gt;Hello. I would like to create a counter variable based on a condition. I would like to begin the counter variable at the first.Date for the first.ID. Within each ID, the counter should count forward and then reset when the Date is more than 280 days from the where the counter started.&amp;nbsp; Then do the same thing for the next ID- start at 1 in the first observation for that ID and count forward until the Date is &amp;gt;280 days from the original date and then restart. Could someone assist me with the code to execute this? Thank you&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data want;
input ID Date YYMMDD10. counter;
format Date YYMMDD10.;
datalines;
1  2014-12-01   1
1  2015-12-31   2
1  2015-12-16   1
1  2015-12-18   2
2  2016-02-23   1
2  2018-03-05   1
2  2018-03-06   2
2  2018-03-25   3
3  2019-05-06   1
3  2019-08-08   2
3  2019-11-08   3
3  2019-11-25   4
3  2020-08-21   1
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2022 03:35:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counter-Reset-After-Condition/m-p/799726#M314481</guid>
      <dc:creator>eabc0351</dc:creator>
      <dc:date>2022-03-03T03:35:22Z</dc:date>
    </item>
    <item>
      <title>Re: Counter Reset After Condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counter-Reset-After-Condition/m-p/799729#M314484</link>
      <description>&lt;P&gt;You either need to check your dates or go into more detail on what your "reset" rules actually are.&lt;/P&gt;
&lt;P&gt;Consider the points indicate below with &amp;lt;=&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;data want;
input ID Date YYMMDD10. counter;
format Date YYMMDD10.;
datalines;
1  2014-12-01   1
1  2015-12-31   2
1  2015-12-16   1 &amp;lt;= within 280 days of 2014-12-01
1  2015-12-18   2 &amp;lt;= within 280 days of 2014-12-01 
2  2016-02-23   1
2  2018-03-05   1
2  2018-03-06   2
2  2018-03-25   3
3  2019-05-06   1
3  2019-08-08   2
3  2019-11-08   3
3  2019-11-25   4
3  2020-08-21   1
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;This comes close except for the points in question above.&lt;/P&gt;
&lt;PRE&gt;data have;
input ID Date :YYMMDD10. ;
format Date YYMMDD10.;
datalines;
1  2014-12-01
1  2015-12-31
1  2015-12-16
1  2015-12-18
2  2016-02-23
2  2018-03-05
2  2018-03-06
2  2018-03-25
3  2019-05-06
3  2019-08-08
3  2019-11-08
3  2019-11-25
3  2020-08-21
;

data want;
   set have;
   by id;
   retain counter basedate;
   if first.id then do;
      /* reset stuff*/
      basedate=date;
      counter=0;
   end;
   if intck('day',basedate,date) le 280 then counter+1;
   else do;
      counter=1;
      /* questionable as to when this resets*/
      basedate=date;
   end;
   drop basedate ;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Mar 2022 04:19:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counter-Reset-After-Condition/m-p/799729#M314484</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-03-03T04:19:35Z</dc:date>
    </item>
    <item>
      <title>Re: Counter Reset After Condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counter-Reset-After-Condition/m-p/799839#M314556</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;.&amp;nbsp;This solution worked great. Yes, I made an error in the datalines for the last two observations for person 1. Thanks again.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2022 13:44:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counter-Reset-After-Condition/m-p/799839#M314556</guid>
      <dc:creator>eabc0351</dc:creator>
      <dc:date>2022-03-03T13:44:45Z</dc:date>
    </item>
  </channel>
</rss>

