<?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: Rolling 12 month Count across Years of Customers in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/532691#M145978</link>
    <description>&lt;P&gt;Thanks for the solution Erik.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To answer the white elephant in the room, yes I did want to count any customers with a transaction within the 12 month period, did not translate the answer I provided mkeintz to the data.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Took some time to play around with this today, it gave me the output I was looking for.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Big thanks to everyone for looking at this.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 04 Feb 2019 19:37:04 GMT</pubDate>
    <dc:creator>RickyS</dc:creator>
    <dc:date>2019-02-04T19:37:04Z</dc:date>
    <item>
      <title>Rolling 12 month Count across Years of Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/531736#M145599</link>
      <description>&lt;P&gt;I need to create a rolling 12 month count of active customers retaining each 12 month count as a new variable.&amp;nbsp; The first rolling 12 months would simply be Year 1.&amp;nbsp; &amp;nbsp;The second rolling 12 month count would be Year 1 months 2 - 12 and Year 2 month 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Reading through various examples with arrays if then do statements and and proc expand and still not able to get to the finish line most of the examples are calculating new numeric variables vs counting character values.&amp;nbsp; At this point I'm confused on what the best methodology is other than the one that produces the output.&amp;nbsp; Here is some sample data, the actual data set spans 19 years, so numerous calculated new variables would results Output would be M1 to M?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data abc;&lt;BR /&gt;input a_id 1. name $ 3 - 11 date mmddyy10. b_id 6.;&lt;BR /&gt;format date mmddyy10.;&lt;BR /&gt;cards;&lt;BR /&gt;1 example1 01/28/2001 123456&lt;BR /&gt;1 example1 02/01/2001 123457&lt;BR /&gt;1 example1 02/18/2001 123458&lt;BR /&gt;1 example1 02/19/2001 123459&lt;BR /&gt;1 example1 02/21/2001 123460&lt;BR /&gt;1 example1 02/26/2001 123461&lt;BR /&gt;1 example1 03/02/2001 123462&lt;BR /&gt;1 example1 04/01/2001 123463&lt;BR /&gt;1 example1 05/15/2001 123464&lt;BR /&gt;1 example1 06/01/2001 123465&lt;BR /&gt;1 example1 06/23/2001 123466&lt;BR /&gt;1 example1 06/26/2001 123467&lt;BR /&gt;1 example1 07/01/2001 123468&lt;BR /&gt;1 example1 07/18/2001 123469&lt;BR /&gt;2 Example2 01/01/2002 123470&lt;BR /&gt;2 Example2 01/28/2002 123471&lt;BR /&gt;2 Example2 02/18/2002 123472&lt;BR /&gt;2 Example2 02/19/2002 123473&lt;BR /&gt;2 Example2 02/26/2002 123474&lt;BR /&gt;2 Example2 03/02/2002 123475&lt;BR /&gt;2 Example2 05/11/2002 123476&lt;BR /&gt;2 Example2 05/15/2002 123477&lt;BR /&gt;2 Example2 06/23/2002 123478&lt;BR /&gt;2 Example2 06/30/2002 123479&lt;BR /&gt;2 Example2 07/01/2002 123480&lt;BR /&gt;2 Example2 07/16/2002 123481&lt;BR /&gt;2 Example2 08/01/2002 123482&lt;BR /&gt;2 Example2 12/31/2002 123483&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jan 2019 17:46:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/531736#M145599</guid>
      <dc:creator>RickyS</dc:creator>
      <dc:date>2019-01-31T17:46:58Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling 12 month Count across Years of Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/531738#M145601</link>
      <description>&lt;P&gt;Do you have a SAS/ETS license?&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jan 2019 17:49:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/531738#M145601</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-01-31T17:49:42Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling 12 month Count across Years of Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/531747#M145608</link>
      <description>&lt;P&gt;yes I have sas/ets&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jan 2019 18:25:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/531747#M145608</guid>
      <dc:creator>RickyS</dc:creator>
      <dc:date>2019-01-31T18:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling 12 month Count across Years of Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/531748#M145609</link>
      <description>&lt;P&gt;Is &lt;STRONG&gt;a_id&lt;/STRONG&gt; / &lt;STRONG&gt;name&lt;/STRONG&gt; a customer ID / name and &lt;STRONG&gt;date&lt;/STRONG&gt;&amp;nbsp;a transaction date for this customer, so each observation counts as 1 in the summation? - what is &lt;STRONG&gt;b_id&lt;/STRONG&gt;? -&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jan 2019 18:26:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/531748#M145609</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-01-31T18:26:55Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling 12 month Count across Years of Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/531753#M145612</link>
      <description>&lt;P&gt;Please post the expected output along with your input sample, that can help somebody test their code results against the expected results. Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jan 2019 18:47:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/531753#M145612</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-01-31T18:47:44Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling 12 month Count across Years of Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/531771#M145625</link>
      <description>&lt;P&gt;Here is an expected Output the M() values would continue until a rolling 12 month count until they could no longer be calculated&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Period&lt;/TD&gt;&lt;TD&gt;Count_of_Customers&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;M1(1/28/2001 - 12/31/2001)&lt;/TD&gt;&lt;TD&gt;14&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;M2(2/1/2001 - 1/31/2002)&lt;/TD&gt;&lt;TD&gt;15&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;M3(3/1/2001 - 2/28/2002)&lt;/TD&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;M4(4/1/2001 - 3/30/2002)&lt;/TD&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jan 2019 19:33:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/531771#M145625</guid>
      <dc:creator>RickyS</dc:creator>
      <dc:date>2019-01-31T19:33:22Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling 12 month Count across Years of Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/531773#M145627</link>
      <description>&lt;P&gt;a_id&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;is a customer id cleaned up so that it is distinct by date and b_id&lt;/P&gt;&lt;P&gt;date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;is equivalent to a transaction date, I've cleaned this up so that it is a max trans date for the mmddyyyy&lt;/P&gt;&lt;P&gt;b_id&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;is the id of the transaction&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jan 2019 19:23:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/531773#M145627</guid>
      <dc:creator>RickyS</dc:creator>
      <dc:date>2019-01-31T19:23:09Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling 12 month Count across Years of Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/531809#M145641</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67527"&gt;@RickyS&lt;/a&gt;&amp;nbsp; Sorry that I am dumb. I have partially understood but not quite there. Can you post the output for just id=1 in full if you have sometime. That will help me figure out&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jan 2019 20:47:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/531809#M145641</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-01-31T20:47:40Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling 12 month Count across Years of Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/532008#M145731</link>
      <description>&lt;P&gt;Thank you for your patience as we try to get on the same page.&amp;nbsp; I created more detailed variable names in&amp;nbsp;hopes that it&amp;nbsp;will help in the explanation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 15 years of customer data, that includes a customer_id,&amp;nbsp;customer_name and customer_product_id all of which are&amp;nbsp;distinct for any&amp;nbsp;transaction_date&amp;nbsp;but may repeat&amp;nbsp;across transaction_dates.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to get a rolling 12 month count of customers.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So the first&amp;nbsp;rolling 12 month period&amp;nbsp;M1 would be&amp;nbsp;01/01/2001 - 12/31/2001,&lt;/P&gt;&lt;P&gt;The&amp;nbsp;next rolling 12 month period M2 would be 02/01/2001 - 01/31/2002&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm looking for the count of customer_id or customer_name in buckets of&amp;nbsp;12.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first M1 output from the Data below would be count of customer_id or customer_name for the Period 01/01/2001 - 12/31/2001&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Period&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Count&lt;/P&gt;&lt;P&gt;M1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 14&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the last transaction_date happens to be 07/18/2001 for the sample data I provided but&amp;nbsp;the code would need to&amp;nbsp;count through 12/31/2001 for the actual data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;M2 the count would start in 02/01/2001 and go to 01/31/2002 basically drop Jan 2001 to create a rolling 12 month count.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;hope this helps&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;data abc;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;input customer_id 1. Customer_name $ 3 - 11 transaction_date mmddyy10. customer_product_id 6.;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;format date mmddyy10.;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;cards;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1 Customer1 01/28/2001 123456&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1 Customer1 02/01/2001 123457&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1 Customer1 02/18/2001 123458&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1 Customer1 02/19/2001 123459&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1 Customer1 02/21/2001 123460&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1 Customer1 02/26/2001 123461&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1 Customer1 03/02/2001 123462&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1 Customer1 04/01/2001 123463&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1 Customer1 05/15/2001 123464&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1 Customer1 06/01/2001 123465&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1 Customer1 06/23/2001 123466&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1 Customer1 06/26/2001 123467&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1 Customer1 07/01/2001 123468&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1 Customer1 07/18/2001 123469&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2 Customer2 01/01/2002 123470&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2 Customer2 01/28/2002 123471&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2 Customer2 02/18/2002 123472&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2 Customer2 02/19/2002 123473&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2 Customer2 02/26/2002 123474&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2 Customer2 03/02/2002 123475&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2 Customer2 05/11/2002 123476&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2 Customer2 05/15/2002 123477&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2 Customer2 06/23/2002 123478&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2 Customer2 06/30/2002 123479&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2 Customer2 07/01/2002 123480&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2 Customer2 07/16/2002 123481&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2 Customer2 08/01/2002 123482&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2 Customer2 12/31/2002 123483&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;run;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Fri, 01 Feb 2019 14:21:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/532008#M145731</guid>
      <dc:creator>RickyS</dc:creator>
      <dc:date>2019-02-01T14:21:20Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling 12 month Count across Years of Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/532228#M145826</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67527"&gt;@RickyS&lt;/a&gt;&amp;nbsp; &amp;nbsp;Thank you . I think I have an idea now. Right now, it;s 5:30 PM Central time(Chicago). I will give it a shot later tonight or tomorrow morning as I have been busy all day. Sorry about the delay&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 23:23:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/532228#M145826</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-01T23:23:34Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling 12 month Count across Years of Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/532252#M145837</link>
      <description>&lt;P&gt;It's still not clear to me how many rolling 12-months windows you want.&amp;nbsp; So here are my questions:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL style="list-style-position: inside;"&gt;
&lt;LI&gt;What should be the starting date of the first 12-month window for a customer id?
&lt;OL&gt;
&lt;LI&gt;is it the 1st of&amp;nbsp; the month of the first record?&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;LI&gt;What should be the ending date of the last 12-month window?
&lt;OL&gt;
&lt;LI&gt;is it the end of the month of the last record for the id?&lt;/LI&gt;
&lt;LI&gt;is it the end of the month 11 months after that last record?&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;LI&gt;If you have an id in which the first and last records do not span 12 months, should that id be ignored?&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a program that &lt;/P&gt;
&lt;OL style="list-style-position: inside;"&gt;
&lt;LI&gt;only does ID's that span at least 12 months&lt;/LI&gt;
&lt;LI&gt;does not create any window that begins in a month prior to the first record.&lt;/LI&gt;
&lt;LI&gt;does not create any window that ends in a month after the last record&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;So, in the case of your sample data, this program creates only one window record, for ID 2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data abc;
  input customer_id 1. Customer_name $ 3 - 11 transaction_date :mmddyy10. customer_product_id 6.;
  format transaction_date mmddyy10.;
datalines;
1 Customer1 01/28/2001 123456
1 Customer1 02/01/2001 123457
1 Customer1 02/18/2001 123458
1 Customer1 02/19/2001 123459
1 Customer1 02/21/2001 123460
1 Customer1 02/26/2001 123461
1 Customer1 03/02/2001 123462
1 Customer1 04/01/2001 123463
1 Customer1 05/15/2001 123464
1 Customer1 06/01/2001 123465
1 Customer1 06/23/2001 123466
1 Customer1 06/26/2001 123467
1 Customer1 07/01/2001 123468
1 Customer1 07/18/2001 123469
2 Customer2 01/01/2002 123470
2 Customer2 01/28/2002 123471
2 Customer2 02/18/2002 123472
2 Customer2 02/19/2002 123473
2 Customer2 02/26/2002 123474
2 Customer2 03/02/2002 123475
2 Customer2 05/11/2002 123476
2 Customer2 05/15/2002 123477
2 Customer2 06/23/2002 123478
2 Customer2 06/30/2002 123479
2 Customer2 07/01/2002 123480
2 Customer2 07/16/2002 123481
2 Customer2 08/01/2002 123482
2 Customer2 12/31/2002 123483
run;

data want (keep=customer_id window_end_date _12month_customer_count  cutoff_date);
  set abc (keep=customer_id);
  by customer_id;
  merge abc
        abc (firstobs=2  keep=transaction_date rename=(transaction_date=nxt_date));

  array mnth_counts {12} _temporary_;  /*Rolling monthly counts */

  if first.customer_id then do;
    call missing (of mnth_counts{*},curr_count);
    cutoff_date=intnx('month',transaction_date,11,'E');
    retain cutoff_date ; format cutoff_date date9.;
    put cutoff_date=;
  end;

  curr_count+1;
  if last.customer_id then months_to_nxt=1;
  else months_to_nxt=intck('month',transaction_date,nxt_date);

  if months_to_nxt&amp;gt;0 or last.customer_id=1 then do step=0 to months_to_nxt-1;
    window_end_date=intnx('month',transaction_date,step,'E');
    format window_end_date date9.;
    m=month(window_end_date);
    mnth_counts{m}=coalesce(curr_count,0);
    curr_count=.;
    _12month_customer_count=sum(of mnth_counts{*});
    if window_end_date&amp;gt;=cutoff_date then output;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The SET statement keep only one variable (CUSTOMER_ID), which is done so that the accompanying BY statement generates the first.customer_id and last.customer_id dummies,so as to know when the record-in-hand is the first one for an ID (when a cutoff_date can be generated for the earliest window-ending date), or when the record-in-hand is the last one for an ID (to determine the ending date of the last possible window). &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The MERGE statement reads all the variables from the current record and one variable (transaction_date renamed to nxt_date) from the next record. This provides a way to determine whether the current record is the last one for a given month.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Twelve monthly totals are maintained in an array.&amp;nbsp; Every time you reach the end of the current month, it's count is used to update the corresponding array element, and the 12-month array total is output (if the window_end_date does not precede the cutoff_date).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the next&amp;nbsp; record is 2 or more months after the current record, additional windows are output, after setting the corresponding "retired" array element to zero.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Feb 2019 02:14:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/532252#M145837</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-02-02T02:14:59Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling 12 month Count across Years of Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/532254#M145838</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;What should be the starting date of the first 12-month window for a customer id?&lt;OL&gt;&lt;LI&gt;is it the 1st of&amp;nbsp; the month of the first record? &lt;STRONG&gt;Yes,&lt;/STRONG&gt;&amp;nbsp;&lt;STRONG&gt;For the sample data 01/01/2001 actual data set 01/01/1999&lt;/STRONG&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;What should be the ending date of the last 12-month window?&lt;OL&gt;&lt;LI&gt;is it the end of the month of the last record for the id?&amp;nbsp; &lt;STRONG&gt;actual data&amp;nbsp;12/31/2017&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;is it the end of the month 11 months after that last record? &lt;STRONG&gt;12 months total so 11 months after the first month&lt;/STRONG&gt;&amp;nbsp;&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;If you have an id in which the first and last records do not span 12 months, should that id be ignored?&amp;nbsp; Y&lt;STRONG&gt;es, However, for the actual data the last rolling 12 month is 01/01/2017 to 12/31/2017, when I mapped it out in EXCEL assuming I did not make a mistake, it came out exactly through sheer dumb luck&amp;nbsp;&lt;/STRONG&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;The output I'm looking for is a single table that should have 248 observations&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Periods&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Count&lt;/P&gt;&lt;P&gt;M1&lt;/P&gt;&lt;P&gt;M248&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Feb 2019 03:48:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/532254#M145838</guid>
      <dc:creator>RickyS</dc:creator>
      <dc:date>2019-02-02T03:48:05Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling 12 month Count across Years of Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/532272#M145843</link>
      <description>&lt;P&gt;Hi RickyS&lt;/P&gt;
&lt;P&gt;From your examples (expected count of 14 in first period) I assume that the expected output is the number of &lt;U&gt;sales transactions&lt;/U&gt; in a rolling 12 month period, regardless of who the customer was. So I am corious about your answer to mkeintz:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"&lt;SPAN&gt;If you have an id in which the first and last records do not span 12 months, should that id be ignored?&amp;nbsp; Yes" &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you really want to exculde customers from counting, if they have not been customers for at least a year, regardless of how many purchases they made? - this would also exclude any new customers from counting, until they had been on your customer list for at least a year?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I spent my evening writing a program that works according to the following rules:&lt;/P&gt;
&lt;OL style="list-style-position: inside;"&gt;
&lt;LI&gt;Wanted output is number of customer transactions in rolling 12 month periods.&lt;/LI&gt;
&lt;LI&gt;A period has a time window covering 12 months.&lt;/LI&gt;
&lt;LI&gt;First period is starting with the month of first transaction in input data and covers the following 11 months.&lt;/LI&gt;
&lt;LI&gt;Last period is ending with the month of last transaction in input data&amp;nbsp;and covers the preceding 11 months.&lt;/LI&gt;
&lt;LI&gt;All transactions count as one in all periods where the transaction month fits into the period window.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;I woke up this morning to find that mkeintz had contributed with a program, that basically does the same, but I post it because it actually makes the output I &lt;U&gt;think&lt;/U&gt; you want, and you might find it useful in your actual coding, as it might be a little easier to modify to suit your needs. The number of periods is determined from the above mentioned rules applied to actual input data, so from the sample data, you only get 13 and not 248 periods.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data abc;
	input customer_id 1. @3 Customer_name $9. @13 transaction_date mmddyy10. @24 customer_product_id 6.; 
	format transaction_date mmddyy10.; 
cards; 
1 Customer1 01/28/2001 123456 
1 Customer1 02/01/2001 123457 
1 Customer1 02/18/2001 123458 
1 Customer1 02/19/2001 123459 
1 Customer1 02/21/2001 123460 
1 Customer1 02/26/2001 123461 
1 Customer1 03/02/2001 123462 
1 Customer1 04/01/2001 123463 
1 Customer1 05/15/2001 123464 
1 Customer1 06/01/2001 123465 
1 Customer1 06/23/2001 123466 
1 Customer1 06/26/2001 123467 
1 Customer1 07/01/2001 123468 
1 Customer1 07/18/2001 123469 
2 Customer2 01/01/2002 123470 
2 Customer2 01/28/2002 123471 
2 Customer2 02/18/2002 123472 
2 Customer2 02/19/2002 123473 
2 Customer2 02/26/2002 123474 
2 Customer2 03/02/2002 123475 
2 Customer2 05/11/2002 123476 
2 Customer2 05/15/2002 123477 
2 Customer2 06/23/2002 123478 
2 Customer2 06/30/2002 123479 
2 Customer2 07/01/2002 123480 
2 Customer2 07/16/2002 123481 
2 Customer2 08/01/2002 123482 
2 Customer2 12/31/2002 123483 
; 
run;

/* Get values to use in computation in data step                                      */
/* mstart is day one in month of first transaction_date + 11.                         */
/* mcount is count of months from mstart to month of last transaction_date            */
proc sql noprint;
	select 
		intnx('month',min(transaction_date),11), 
		intck('month',intnx('month',min(transaction_date),11), 
			intnx('month',max(transaction_date),1))
	into :mstart, :mcount
	from abc;
quit;
%put %sysfunc(putn(&amp;amp;mstart,mmddyy10.)) &amp;amp;mcount;

data want; set abc end=eof;
	length Periods $4 Count 8.;
	Keep Periods Count;

	* Array to hold counters - initiate with 0 and retain for summation;
	array transcount 8 m1 - m%eval(&amp;amp;mcount) _temporary_;
	retain m1 - m%eval(&amp;amp;mcount) 0;

	* Offset (month of transaction_date relative to mstart);
	startoffset = intck('month',&amp;amp;mstart,transaction_date); 

	* Loop over 12 months from month of transaction_date;
	* Add count only if count_month is within defined interval;
	do i = 1 to 12;	
		interval = startoffset + i;
		if 0 &amp;lt; interval &amp;lt;= &amp;amp;mcount then do; 
			transcount{interval} = transcount{interval} + 1;
		end;
	end;

	* Transpose array and output when finished;
	if eof then do i = 1 to &amp;amp;mcount;
		Periods = 'M'||left(put(i,3.));
		Count = transcount{i};
		output;
	end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="periods.gif" style="width: 177px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/26793i8DF8CA22218B4B88/image-size/large?v=v2&amp;amp;px=999" role="button" title="periods.gif" alt="periods.gif" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope this will help you. Greetings from Denmark / Erik&lt;/P&gt;</description>
      <pubDate>Sat, 02 Feb 2019 10:08:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/532272#M145843</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-02-02T10:08:17Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling 12 month Count across Years of Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/532309#M145858</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67527"&gt;@RickyS&lt;/a&gt;&amp;nbsp; &amp;nbsp;My attempt&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data abc;
	input customer_id 1. @3 Customer_name $9. @13 transaction_date mmddyy10. @24 customer_product_id 6.; 
	format transaction_date mmddyy10.; 
cards; 
1 Customer1 01/28/2001 123456 
1 Customer1 02/01/2001 123457 
1 Customer1 02/18/2001 123458 
1 Customer1 02/19/2001 123459 
1 Customer1 02/21/2001 123460 
1 Customer1 02/26/2001 123461 
1 Customer1 03/02/2001 123462 
1 Customer1 04/01/2001 123463 
1 Customer1 05/15/2001 123464 
1 Customer1 06/01/2001 123465 
1 Customer1 06/23/2001 123466 
1 Customer1 06/26/2001 123467 
1 Customer1 07/01/2001 123468 
1 Customer1 07/18/2001 123469 
2 Customer2 01/01/2002 123470 
2 Customer2 01/28/2002 123471 
2 Customer2 02/18/2002 123472 
2 Customer2 02/19/2002 123473 
2 Customer2 02/26/2002 123474 
2 Customer2 03/02/2002 123475 
2 Customer2 05/11/2002 123476 
2 Customer2 05/15/2002 123477 
2 Customer2 06/23/2002 123478 
2 Customer2 06/30/2002 123479 
2 Customer2 07/01/2002 123480 
2 Customer2 07/16/2002 123481 
2 Customer2 08/01/2002 123482 
2 Customer2 12/31/2002 123483 
; 
run;

proc means data=abc nway noprint;
var transaction_date;
output out=w(drop=_:) min= max=/autoname;
run;
data start_and_end;
set w;
start=transaction_date_min;
do while(start&amp;lt;transaction_date_max);
end=intnx('month',start,11,'e') ;
output;
start=intnx('month',start,1);
end;
keep start end;
format start end mmddyy10.;
run;&lt;BR /&gt;
data want;
period=cats('M',_n_);
if _n_=1 then do;
if 0 then set abc;
   dcl hash H (dataset:'abc',multidata:'y') ;
   h.definekey  ("customer_id") ;
   h.definedata ("transaction_date") ;
   h.definedone () ;
   dcl hiter hh('h');
 end;
 set start_and_end;
 c=0;
 do while(hh.next()=0);
 if   start &amp;lt;=transaction_date&amp;lt;=end then c+1;
 end;
 keep period start end c;
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 02 Feb 2019 18:58:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/532309#M145858</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-02T18:58:52Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling 12 month Count across Years of Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/532691#M145978</link>
      <description>&lt;P&gt;Thanks for the solution Erik.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To answer the white elephant in the room, yes I did want to count any customers with a transaction within the 12 month period, did not translate the answer I provided mkeintz to the data.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Took some time to play around with this today, it gave me the output I was looking for.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Big thanks to everyone for looking at this.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 19:37:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/532691#M145978</guid>
      <dc:creator>RickyS</dc:creator>
      <dc:date>2019-02-04T19:37:04Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling 12 month Count across Years of Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/532697#M145979</link>
      <description>&lt;P&gt;Novinosrin,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your solution works as well and I appreciate that you took some time over the weekend to look at it also nice that you included the defined period as part of the output.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 19:47:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/532697#M145979</guid>
      <dc:creator>RickyS</dc:creator>
      <dc:date>2019-02-04T19:47:26Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling 12 month Count across Years of Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/665320#M198912</link>
      <description>Hello Everyone,&lt;BR /&gt;&lt;BR /&gt;I have a similar but slight different concern in my data. Basically I am looking to create a sequence variable based on two columns : Cust_name and Year.&lt;BR /&gt;There are different type of customers as below:&lt;BR /&gt;Customer1 was with me from 2001 to 2003&lt;BR /&gt;Customer2 was with me only for 2001 and 2002&lt;BR /&gt;Customer3 was only for one year 2001&lt;BR /&gt;Customer4 was with me alternate year 2003,2005,2007&lt;BR /&gt;Customer5 2001,2002,2005,2006,2007&lt;BR /&gt;&lt;BR /&gt;I want to find maximum number of years I was able to provide service to my customers.&lt;BR /&gt;So, Output I am looking is:&lt;BR /&gt;Customer1 output as 3 (as he was 2001,2002,2003)&lt;BR /&gt;Customer2 as 2 (as he was 2001,2002)&lt;BR /&gt;Customer3 as 1 (as he was only for yr 2001)&lt;BR /&gt;Customer4 as 1 (alternate yr so no continuous year)&lt;BR /&gt;Customer5 as 3 ( he was there continuously 2(2001,2002) and 3(2005,2006,2007) so I will choose max as 3).&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;PFB dataset for your reference:&lt;BR /&gt;&lt;BR /&gt;data abc;&lt;BR /&gt;input customer_id Customer_name $ 3 - 11 transaction_date :mmddyy10. ;&lt;BR /&gt;format transaction_date mmddyy10.;&lt;BR /&gt;datalines;&lt;BR /&gt;1 Customer1 03/31/2001&lt;BR /&gt;1 Customer1 03/31/2002&lt;BR /&gt;1 Customer1 03/31/2003&lt;BR /&gt;2 Customer2 03/31/2001&lt;BR /&gt;2 Customer2 03/31/2002&lt;BR /&gt;3 Customer3 03/31/2001&lt;BR /&gt;4 Customer4 03/31/2003&lt;BR /&gt;4 Customer4 03/31/2005&lt;BR /&gt;4 Customer4 03/31/2007&lt;BR /&gt;5 Customer5 03/31/2001&lt;BR /&gt;5 Customer5 03/31/2002&lt;BR /&gt;5 Customer5 03/31/2005&lt;BR /&gt;5 Customer5 03/31/2006&lt;BR /&gt;5 Customer5 03/31/2007&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc print data=abc;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Looking forward for the insights.&lt;BR /&gt;Thanks in advance! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 26 Jun 2020 12:02:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/665320#M198912</guid>
      <dc:creator>AkshayS</dc:creator>
      <dc:date>2020-06-26T12:02:15Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling 12 month Count across Years of Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/665389#M198956</link>
      <description>&lt;P&gt;I suggest you start a new topic, with a complete description of your objective, rather that "I want the same except ...". It will be far easier for us to help you.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jun 2020 15:26:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/665389#M198956</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-06-26T15:26:20Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling 12 month Count across Years of Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/665399#M198964</link>
      <description>Sure Sir. Please find the below subject line with new post. Looking forward for your recommendations. To identify the continuity and loyalty of customer over the years and find maximum continuity year. Thanks in advance!</description>
      <pubDate>Fri, 26 Jun 2020 16:09:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-12-month-Count-across-Years-of-Customers/m-p/665399#M198964</guid>
      <dc:creator>AkshayS</dc:creator>
      <dc:date>2020-06-26T16:09:41Z</dc:date>
    </item>
  </channel>
</rss>

