<?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: New customer based on look back period in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/New-customer-based-on-look-back-period/m-p/348024#M80540</link>
    <description>&lt;P&gt;We have data like this&lt;/P&gt;&lt;P&gt;feb'17 jan'17 dec'16 nov'16 oct'16 sep'16 ...&lt;/P&gt;&lt;P&gt;so first month is feb'17, 2month is jan'17 and so on so look back for Feb'17 will be Jan'17 to Feb'16(12 months look back).&lt;/P&gt;</description>
    <pubDate>Fri, 07 Apr 2017 08:57:50 GMT</pubDate>
    <dc:creator>pawandh</dc:creator>
    <dc:date>2017-04-07T08:57:50Z</dc:date>
    <item>
      <title>New customer based on look back period</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-customer-based-on-look-back-period/m-p/347807#M80436</link>
      <description>&lt;P&gt;&amp;nbsp;I want to create a table where I will have new customer.Suppose a customer purchased something in Feb'17 and prior to 12 months i.e from jan'16-feb'15 customer didn't purchase anythning, then it's a new customer for Feb'17. The look back period is for 12 months.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;cust_id date sales;&lt;/P&gt;&lt;P&gt;001 23feb2017 100&lt;/P&gt;&lt;P&gt;001 22jan2016 200&lt;/P&gt;&lt;P&gt;001 23mar2017 300&lt;/P&gt;&lt;P&gt;002 01june2015 200&lt;/P&gt;&lt;P&gt;002 03aug2016 300&lt;/P&gt;&lt;P&gt;002 05april2016 400&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;output should be&lt;/P&gt;&lt;P&gt;new_cust date sales;&lt;/P&gt;&lt;P&gt;001 23feb2017 100&lt;/P&gt;&lt;P&gt;002 05april2016 400&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I do using SAS or SQL&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2017 15:57:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-customer-based-on-look-back-period/m-p/347807#M80436</guid>
      <dc:creator>pawandh</dc:creator>
      <dc:date>2017-04-06T15:57:41Z</dc:date>
    </item>
    <item>
      <title>Re: New customer based on look back period</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-customer-based-on-look-back-period/m-p/347820#M80443</link>
      <description>&lt;P&gt;I'm a bit confused regarding your example. If you put your dates in descending order (i.e.,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;cust_id date sales;&lt;/P&gt;
&lt;P&gt;001 23mar2017 300&lt;/P&gt;
&lt;P&gt;001 23feb2017 100&lt;/P&gt;
&lt;P&gt;001 22jan2016 200&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;002 03aug2016 300&lt;/P&gt;
&lt;P&gt;002 05april2016 400&lt;/P&gt;
&lt;P&gt;002 01june2015 200&lt;/P&gt;
&lt;P&gt;---------&lt;/P&gt;
&lt;P&gt;001 23feb2017 100 would be the only&amp;nbsp;date that meets your conditions, not&lt;/P&gt;
&lt;P&gt;001 23feb2017 100 and 002 05april2016 400&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is that what you want or did I miss something?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it's what you want, assuming you also would want brand new customers that don't have any gap, I'd guess that you want something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
  input cust_id date date9. sales;
  format date date9.;
  cards;
001 23feb2017 100
001 22jan2016 200
001 23mar2017 300
002 01jun2015 200
002 03aug2016 300
002 05apr2016 400
003 06apr2017 200
;

proc sort data=have;
  by cust_id date;
run;
 
data want (drop=gap);
  set have;
  by cust_id;
  gap = dif(date);
  if (first.cust_id and last.cust_id) or
   (first.cust_id=0 and gap &amp;gt; 365);
run;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2017 16:29:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-customer-based-on-look-back-period/m-p/347820#M80443</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-04-06T16:29:50Z</dc:date>
    </item>
    <item>
      <title>Re: New customer based on look back period</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-customer-based-on-look-back-period/m-p/347821#M80444</link>
      <description>&lt;P&gt;Why should customer 002 appear as a new customer?&amp;nbsp; I don't see a 12-month gap here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming that's a mistake, here's one way.&amp;nbsp; (It uses 365 days as the time period, but that can be made more accurate if you need to account for leap years.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;/P&gt;
&lt;P&gt;informat date date9.;&lt;/P&gt;
&lt;P&gt;input cust_id $ date sales;&lt;/P&gt;
&lt;P&gt;format date date9.;&lt;/P&gt;
&lt;P&gt;datalines;&lt;/P&gt;
&lt;P&gt;001 23feb2017 100&lt;/P&gt;
&lt;P&gt;001 22jan2016 200&lt;/P&gt;
&lt;P&gt;001 23mar2017 300&lt;/P&gt;
&lt;P&gt;002 01&lt;FONT color="#ff0000"&gt;jun&lt;/FONT&gt;2015 200&lt;/P&gt;
&lt;P&gt;002 03aug2016 300&lt;/P&gt;
&lt;P&gt;002 05&lt;FONT color="#ff0000"&gt;apr&lt;/FONT&gt;2016 400&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=have;&lt;/P&gt;
&lt;P&gt;by cust_id date;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by cust_id;&lt;/P&gt;
&lt;P&gt;gap = dif(date);&lt;/P&gt;
&lt;P&gt;if &lt;FONT color="#339966"&gt;(first.cust_id) or (&lt;/FONT&gt;first.cust_id=0 and gap &amp;gt; 365&lt;FONT color="#339966"&gt;)&lt;/FONT&gt;;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that the data should contain just the first three letters of the month.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#339966"&gt;OK, modified the program to match what it seems you are looking for.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2017 11:18:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-customer-based-on-look-back-period/m-p/347821#M80444</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-04-07T11:18:38Z</dc:date>
    </item>
    <item>
      <title>Re: New customer based on look back period</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-customer-based-on-look-back-period/m-p/347875#M80462</link>
      <description>&lt;P&gt;Here for customer 002, new writer flag would be in JUN'15 as this is the most recent month where customer purchased anything and prior to that &amp;nbsp;12 month customer didn't buy anything.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let's say you purchased something &amp;nbsp;on Feb'17 and Mar'17,now you are a new customer in Feb'17 because from the past 12 months you didn't purchase anything.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2017 18:54:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-customer-based-on-look-back-period/m-p/347875#M80462</guid>
      <dc:creator>pawandh</dc:creator>
      <dc:date>2017-04-06T18:54:03Z</dc:date>
    </item>
    <item>
      <title>Re: New customer based on look back period</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-customer-based-on-look-back-period/m-p/347880#M80465</link>
      <description>&lt;P&gt;OK, which of these would be a better solution?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The earliest record for each customer, plus all later records that have at least a 365-day gap.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;vs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For each customer, all records that have a 365-day gap.&amp;nbsp; If there are none, then use the earliest record instead.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2017 18:59:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-customer-based-on-look-back-period/m-p/347880#M80465</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-04-06T18:59:29Z</dc:date>
    </item>
    <item>
      <title>Re: New customer based on look back period</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-customer-based-on-look-back-period/m-p/347885#M80468</link>
      <description>&lt;P&gt;Now I'm more confused. According to your most recent post, all customers are being considered as new customers. They are considered new as of the most recent date of:&lt;/P&gt;
&lt;P&gt;1. the first date they did business with you&lt;/P&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;2. the most recent date that came after a year period where they didn't do any business with you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is that what you are trying to get?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2017 19:17:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-customer-based-on-look-back-period/m-p/347885#M80468</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-04-06T19:17:36Z</dc:date>
    </item>
    <item>
      <title>Re: New customer based on look back period</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-customer-based-on-look-back-period/m-p/347905#M80480</link>
      <description>For customer 2, can you explain how criteria work please ?&lt;BR /&gt;&lt;BR /&gt;002 01june2015 200...gap=start point&lt;BR /&gt;002 05april2016 400...gap&amp;lt;365&lt;BR /&gt;002 03aug2016 300...gap&amp;lt;365&lt;BR /&gt;</description>
      <pubDate>Thu, 06 Apr 2017 19:56:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-customer-based-on-look-back-period/m-p/347905#M80480</guid>
      <dc:creator>Yavuz</dc:creator>
      <dc:date>2017-04-06T19:56:40Z</dc:date>
    </item>
    <item>
      <title>Re: New customer based on look back period</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-customer-based-on-look-back-period/m-p/347980#M80510</link>
      <description>&lt;P&gt;Suppose you are a customer, and you purchased in Feb'17,Mar'17 and so on. You start purchasing in Feb'17 so you are starting from that month, new customer for that month. And will check prior to that 12 months do you have any record or not. So if you purchased in Aug'16 as well then for Aug'16 you will be a new customer not for Feb'17.&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>Fri, 07 Apr 2017 04:59:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-customer-based-on-look-back-period/m-p/347980#M80510</guid>
      <dc:creator>pawandh</dc:creator>
      <dc:date>2017-04-07T04:59:38Z</dc:date>
    </item>
    <item>
      <title>Re: New customer based on look back period</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-customer-based-on-look-back-period/m-p/347982#M80512</link>
      <description>&lt;P&gt;Customer 002 has purchased on aug2016, now check any purchase prior to 12 months. So the purchase is on april2016,now look again &amp;nbsp;back for 12 months, purchase is on june2015. And prior to jun2015 there is no purchase so jun'15 is the month where 002 started purchaisng ,now for this month customer is new .&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2017 05:07:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-customer-based-on-look-back-period/m-p/347982#M80512</guid>
      <dc:creator>pawandh</dc:creator>
      <dc:date>2017-04-07T05:07:34Z</dc:date>
    </item>
    <item>
      <title>Re: New customer based on look back period</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-customer-based-on-look-back-period/m-p/347985#M80513</link>
      <description>But between jun15 and april 16 there is not 12 month period. Can you tell me what is the difference of jun15 and april16.</description>
      <pubDate>Fri, 07 Apr 2017 05:51:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-customer-based-on-look-back-period/m-p/347985#M80513</guid>
      <dc:creator>Yavuz</dc:creator>
      <dc:date>2017-04-07T05:51:04Z</dc:date>
    </item>
    <item>
      <title>Re: New customer based on look back period</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-customer-based-on-look-back-period/m-p/348024#M80540</link>
      <description>&lt;P&gt;We have data like this&lt;/P&gt;&lt;P&gt;feb'17 jan'17 dec'16 nov'16 oct'16 sep'16 ...&lt;/P&gt;&lt;P&gt;so first month is feb'17, 2month is jan'17 and so on so look back for Feb'17 will be Jan'17 to Feb'16(12 months look back).&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2017 08:57:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-customer-based-on-look-back-period/m-p/348024#M80540</guid>
      <dc:creator>pawandh</dc:creator>
      <dc:date>2017-04-07T08:57:50Z</dc:date>
    </item>
  </channel>
</rss>

