<?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: help to count with conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/help-to-count-with-conditions/m-p/723226#M224395</link>
    <description>&lt;P&gt;Or even simpler I suppose:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
 set temp;
 by ID DATE ;

 if not first.ID and dif(date) &amp;lt; 5
  then cflag+1;
  else cflag=1;     
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
    <pubDate>Wed, 03 Mar 2021 17:54:07 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2021-03-03T17:54:07Z</dc:date>
    <item>
      <title>help to count with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-to-count-with-conditions/m-p/723211#M224383</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my database has millions of register with different IDs, i will show just an example with one ID.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
infile DATALINES dsd missover;
input DATE:DDMMYY10. value_payment ID;
FORMAT DATE DDMMYY10.;
CARDS;
16/11/2020,9000,1
02/12/2020,9000,1
03/12/2020,8000,1
03/12/2020,6000,1
03/12/2020,5000,1
03/12/2020,1000,1
07/12/2020,2000,1
29/12/2020,3000,1
29/12/2020,4000,1
29/12/2020,9999,1
29/12/2020,2000,1
26/01/2021,5000,1
26/01/2021,1111,1
26/01/2021,1000,1
01/02/2021,2000,1
01/02/2021,3000,1
01/02/2021,1000,1
02/02/2021,5000,1
02/02/2021,7000,1
02/02/2021,8000,1
02/02/2021,9000,1
08/02/2021,10000,1
08/02/2021,1000,1
08/02/2021,4444,1
01/06/2020,3000,1
;
run;

PROC SORT DATA=temp;
	BY DATE ID;
RUN;

data test;
 set temp;
 FORMAT tempdate ddmmyy10.;
 by ID DATE ;
 tempdate=lag(DATE);
 if first.ID then tempdate=DATE;
 retain cflag;
 if first.ID then cflag=0;
 if DATE &amp;lt; INTNX('DAY',tempdate,5) then cflag=cflag+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My difficulty is to count only if the ID is the same and the first date cannot be longer than 05 days compared to the second date, because i need to identify 4 or more payments within 5 or more days.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Result of my code:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sk1_SAS_0-1614791499105.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55402i14BE21083BEFA942/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Sk1_SAS_0-1614791499105.png" alt="Sk1_SAS_0-1614791499105.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the result that i need:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;DATE	value_payment	ID	tempdate	cflag
01/06/2020	3000	1	01/06/2020	1
16/11/2020	9000	1	01/06/2020	1
02/12/2020	9000	1	16/11/2020	1
03/12/2020	8000	1	02/12/2020	2
03/12/2020	6000	1	03/12/2020	3
03/12/2020	5000	1	03/12/2020	4
03/12/2020	1000	1	03/12/2020	5
07/12/2020	2000	1	03/12/2020	6
29/12/2020	3000	1	07/12/2020	1
29/12/2020	4000	1	29/12/2020	2
29/12/2020	9999	1	29/12/2020	3
29/12/2020	2000	1	29/12/2020	4
26/01/2021	5000	1	29/12/2020	1
26/01/2021	1111	        1	26/01/2021	2
26/01/2021	1000	1	26/01/2021	3
01/02/2021	2000	1	26/01/2021	1
01/02/2021	3000	1	01/02/2021	2
01/02/2021	1000	1	01/02/2021	3
02/02/2021	5000	1	01/02/2021	4
02/02/2021	7000	1	02/02/2021	5
02/02/2021	8000	1	02/02/2021	6
02/02/2021	9000	1	02/02/2021	7
08/02/2021	10000	1	02/02/2021	1
08/02/2021	1000	1	08/02/2021	2
08/02/2021	4444	1	08/02/2021	3&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Tks!!!!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Mar 2021 17:17:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-to-count-with-conditions/m-p/723211#M224383</guid>
      <dc:creator>Sk1_SAS</dc:creator>
      <dc:date>2021-03-03T17:17:52Z</dc:date>
    </item>
    <item>
      <title>Re: help to count with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-to-count-with-conditions/m-p/723219#M224389</link>
      <description>&lt;P&gt;Do I see corect that you need something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
 set temp;
 by ID DATE ;

 if first.ID then cflag=1;
 else do;
  if dif(date) &amp;lt; 5 then cflag+1;
                   else cflag=1;
 end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Btw. I think sorting should be by ID and DATE, isn't it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 03 Mar 2021 17:38:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-to-count-with-conditions/m-p/723219#M224389</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2021-03-03T17:38:17Z</dc:date>
    </item>
    <item>
      <title>Re: help to count with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-to-count-with-conditions/m-p/723222#M224392</link>
      <description>&lt;P&gt;With this requirement:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;My difficulty is to count only if the ID is the same and the first date cannot be longer than 05 days compared to the second date, because i need to identify 4 or more payments within 5 or more days.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;what do you expect in your output when there do not exist "4 or more payments", such as may happen with a very new ID?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Mar 2021 17:42:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-to-count-with-conditions/m-p/723222#M224392</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-03T17:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: help to count with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-to-count-with-conditions/m-p/723223#M224393</link>
      <description>Thats It! Tks!!!!</description>
      <pubDate>Wed, 03 Mar 2021 17:44:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-to-count-with-conditions/m-p/723223#M224393</guid>
      <dc:creator>Sk1_SAS</dc:creator>
      <dc:date>2021-03-03T17:44:33Z</dc:date>
    </item>
    <item>
      <title>Re: help to count with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-to-count-with-conditions/m-p/723226#M224395</link>
      <description>&lt;P&gt;Or even simpler I suppose:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
 set temp;
 by ID DATE ;

 if not first.ID and dif(date) &amp;lt; 5
  then cflag+1;
  else cflag=1;     
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 03 Mar 2021 17:54:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-to-count-with-conditions/m-p/723226#M224395</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2021-03-03T17:54:07Z</dc:date>
    </item>
  </channel>
</rss>

