<?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 How to count number of of call in the a week in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-count-number-of-of-call-in-the-a-week/m-p/336805#M272493</link>
    <description>&lt;P&gt;Suppose I have sorted sample dataset looks like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CustomerID &amp;nbsp; CallID &amp;nbsp;Date&lt;/P&gt;&lt;P&gt;123 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01/30/2017&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;123 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01/30/2017&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;123 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;02/03/2017&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;123 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;02/07/2017&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;123 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;02/08/2017&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I want to count how many calls did I received from the same customer in the past 7 days as of each date. The desired output dataset would&amp;nbsp;be&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CustomerID &amp;nbsp; CallID &amp;nbsp;Date &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;NumOfCallsInOneWeek&lt;/P&gt;&lt;P&gt;123 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01/30/2017 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;123 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01/30/2017 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;123 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;02/03/2017 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;123 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;02/07/2017 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;123 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;02/08/2017 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Note as of 02/07/2017, the 2 calls on 01/30/2017 are received over a week ago, so they are not counted.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;How could I do it using either data step or proc sql?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Could someone please help me? I'd really appreciate it!!! Thank you!&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 01 Mar 2017 00:48:02 GMT</pubDate>
    <dc:creator>yxs8016</dc:creator>
    <dc:date>2017-03-01T00:48:02Z</dc:date>
    <item>
      <title>How to count number of of call in the a week</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-count-number-of-of-call-in-the-a-week/m-p/336805#M272493</link>
      <description>&lt;P&gt;Suppose I have sorted sample dataset looks like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CustomerID &amp;nbsp; CallID &amp;nbsp;Date&lt;/P&gt;&lt;P&gt;123 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01/30/2017&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;123 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01/30/2017&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;123 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;02/03/2017&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;123 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;02/07/2017&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;123 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;02/08/2017&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I want to count how many calls did I received from the same customer in the past 7 days as of each date. The desired output dataset would&amp;nbsp;be&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CustomerID &amp;nbsp; CallID &amp;nbsp;Date &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;NumOfCallsInOneWeek&lt;/P&gt;&lt;P&gt;123 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01/30/2017 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;123 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01/30/2017 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;123 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;02/03/2017 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;123 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;02/07/2017 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;123 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;02/08/2017 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Note as of 02/07/2017, the 2 calls on 01/30/2017 are received over a week ago, so they are not counted.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;How could I do it using either data step or proc sql?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Could someone please help me? I'd really appreciate it!!! Thank you!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2017 00:48:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-count-number-of-of-call-in-the-a-week/m-p/336805#M272493</guid>
      <dc:creator>yxs8016</dc:creator>
      <dc:date>2017-03-01T00:48:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to count number of of call in the a week</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-count-number-of-of-call-in-the-a-week/m-p/336809#M272494</link>
      <description>&lt;P&gt;I think the number of calls for callId=1 should be two, unless callId represents an ever increasing sequence,. i.e. unless we know that callId=1 occured before callId=2 because 1 &amp;lt; 2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input CustomerID   CallID  Date :mmddyy10.;
format date yymmdd10.;
datalines;
123                1          01/30/2017
123                2          01/30/2017
123                3          02/03/2017
123                4          02/07/2017
123                5          02/08/2017
;

proc sql;
create table want as
select
    a.CustomerID, a.CallID, a.Date,
    count(b.callId) as NumOfCallsInOneWeek
from 
    have as a inner join
    have as b on 
        a.CustomerID=b.CustomerID and
        b.date between intnx("week", a.date, -1, "same") and a.date
group by a.CustomerID, a.CallID, a.Date;
select * from want;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Mar 2017 01:20:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-count-number-of-of-call-in-the-a-week/m-p/336809#M272494</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-03-01T01:20:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to count number of of call in the a week</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-count-number-of-of-call-in-the-a-week/m-p/336910#M272495</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input CustomerID   CallID  Date :mmddyy10.;
format date yymmdd10.;
datalines;
123                1          01/30/2017
123                2          01/30/2017
123                3          02/03/2017
123                4          02/07/2017
123                5          02/08/2017
;
run;
data want;
 set have;
 by customerid;
 array x{9999} _temporary_;
 if first.customerid then do;n=0;call missing(of x{*});end;
 n+1;
 x{n}=date;
 count=0;
 do i=1 to n;
  if date-6&amp;lt;=x{i}&amp;lt;=date then count+1;
 end;
 drop n i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Mar 2017 10:33:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-count-number-of-of-call-in-the-a-week/m-p/336910#M272495</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-03-01T10:33:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to count number of of call in the a week</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-count-number-of-of-call-in-the-a-week/m-p/337053#M272496</link>
      <description>&lt;P&gt;You are right. I should've described it more clearly. I am assuming CallID=1 occured before CallID=2. To be more specific, the column Date should be DateTime.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm sorry that I miss guided you. I really appreciate your response. Thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2017 16:21:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-count-number-of-of-call-in-the-a-week/m-p/337053#M272496</guid>
      <dc:creator>yxs8016</dc:creator>
      <dc:date>2017-03-01T16:21:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to count number of of call in the a week</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-count-number-of-of-call-in-the-a-week/m-p/337054#M272497</link>
      <description>Thank you for your help!</description>
      <pubDate>Wed, 01 Mar 2017 16:22:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-count-number-of-of-call-in-the-a-week/m-p/337054#M272497</guid>
      <dc:creator>yxs8016</dc:creator>
      <dc:date>2017-03-01T16:22:57Z</dc:date>
    </item>
  </channel>
</rss>

