<?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: Identifying Lapsed Customers in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Identifying-Lapsed-Customers/m-p/313553#M68152</link>
    <description>&lt;P&gt;Here's a way you might proceed:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;days_passed = dif(transaction_date);&lt;/P&gt;
&lt;P&gt;if first.mstr_customer_id=0 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if days_passed &amp;lt; 12 * 30 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; else if days_passed &amp;lt; 24 * 30 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; winback_48='Y';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; winback_36='Y';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; winback_24='Y';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; winback_12='Y';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; else if days_passed &amp;lt; 36 * 30 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; winback_24 = 'Y';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; winback_36 = 'Y';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; winback_48 = 'Y';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; ....&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's the idea of it, anyway.&amp;nbsp; I didn't sketch out all the combinations.&amp;nbsp; I hope I got the logic right, but if the results look strange, you can make it simpler by adding comparisons to both sides of the IF/THEN conditions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can adjust the time periods pretty easily.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Remember to subset, taking just the final observation per customer with the final value for the flags.&lt;/P&gt;</description>
    <pubDate>Tue, 22 Nov 2016 18:25:44 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2016-11-22T18:25:44Z</dc:date>
    <item>
      <title>Identifying Lapsed Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-Lapsed-Customers/m-p/313517#M68136</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I have 4 years (48 months) of customer transaction history. The data set includes &lt;STRONG&gt;customer id&lt;/STRONG&gt; and &lt;STRONG&gt;transaction date.&amp;nbsp; &lt;/STRONG&gt;I am want to count the number of customers which have laspsed (not shopped for a period of time) and then shopped again (winback) during the 48 month time period – Look at winback % by # of months of inactivity for 12 months, 18 months, 24 months and 36 months.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, using 18 months: Anyone from the above 48 month group who then made at least one purchase after the 18-month period of inactivity is a won back flag (Target = 1).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then anyone from the above group who did not make a purchase after the 18-month period of inactivity is NOT won back flag (Target = 0).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have written a query which calculates the difference in months between purchases.&amp;nbsp; From here I’m having trouble figuring out how to calculate the flag variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data obs; 
set have;
format l_transaction_date date8.;
retain first_transaction;
by mstr_customer_id transaction_date;
l_transaction_date = lag(transaction_date);
if not first.mstr_customer_id then do;
month_diff = intck('month',l_transaction_date,transaction_date);
end;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;I have attached some sample data and an explanation/example which I am looking for. &amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 16:23:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-Lapsed-Customers/m-p/313517#M68136</guid>
      <dc:creator>Mgarret</dc:creator>
      <dc:date>2016-11-22T16:23:06Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying Lapsed Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-Lapsed-Customers/m-p/313527#M68140</link>
      <description>&lt;P&gt;On a side note, be careful using INTCK.&amp;nbsp; It measures number of boundaries crossed (in this case, first of the month dates).&amp;nbsp; So, for example, if two purchases dates are:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;January 29, 2015&lt;/P&gt;
&lt;P&gt;January 2, 2016&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This would count as 12 months since there are 12 "1st of the month" dates in between.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As an alternative, it's easy to count number of days elapsed:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;transaction_date - l_transaction_date&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and divide that by 30 or by 30.5 to convert to months.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 16:48:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-Lapsed-Customers/m-p/313527#M68140</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-11-22T16:48:25Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying Lapsed Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-Lapsed-Customers/m-p/313533#M68142</link>
      <description>&lt;P&gt;Thanks! &amp;nbsp;Do you have a recommendation or example of how to count the number customers that shopped and then didn’t shop again for another 18 months?&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 17:17:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-Lapsed-Customers/m-p/313533#M68142</guid>
      <dc:creator>Mgarret</dc:creator>
      <dc:date>2016-11-22T17:17:01Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying Lapsed Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-Lapsed-Customers/m-p/313538#M68145</link>
      <description>&lt;P&gt;At a minimum, you would need to add flags for each time period, something along these lines:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if first.mstr_customer_id then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; winback_12='N';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; winback_24='N';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; winback_36='N';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; winback_48='N';&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;retain winback_:;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you would need to add logic that might set these to "Y".&amp;nbsp; The exact logic depends on how you are counting.&amp;nbsp; For example, are you using your original "month" calculations, or are you switching to days?&amp;nbsp; Should the 12-month category being "Y" also force all the other categories to be "Y", or does WINBACK_24 actually refer to customers won back within 19 to 24 months only?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At any rate, decide on the logic to re-set the flags.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally, add:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if last.mstr_customer_id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Keep just the final observation for each customer, with the final setting for all the flags.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 17:43:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-Lapsed-Customers/m-p/313538#M68145</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-11-22T17:43:50Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying Lapsed Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-Lapsed-Customers/m-p/313544#M68148</link>
      <description>&lt;P&gt;Thanks astonding. &amp;nbsp;After reading your reply, I think days would make more sense, and yes, &amp;nbsp;the 12-month category being "Y" also force all the other categories to be "Y”.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I’m a little confused with the syntax.&amp;nbsp; Any additional assistance is greatly appreciated!&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 17:55:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-Lapsed-Customers/m-p/313544#M68148</guid>
      <dc:creator>Mgarret</dc:creator>
      <dc:date>2016-11-22T17:55:11Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying Lapsed Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-Lapsed-Customers/m-p/313553#M68152</link>
      <description>&lt;P&gt;Here's a way you might proceed:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;days_passed = dif(transaction_date);&lt;/P&gt;
&lt;P&gt;if first.mstr_customer_id=0 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if days_passed &amp;lt; 12 * 30 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; else if days_passed &amp;lt; 24 * 30 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; winback_48='Y';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; winback_36='Y';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; winback_24='Y';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; winback_12='Y';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; else if days_passed &amp;lt; 36 * 30 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; winback_24 = 'Y';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; winback_36 = 'Y';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; winback_48 = 'Y';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; ....&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's the idea of it, anyway.&amp;nbsp; I didn't sketch out all the combinations.&amp;nbsp; I hope I got the logic right, but if the results look strange, you can make it simpler by adding comparisons to both sides of the IF/THEN conditions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can adjust the time periods pretty easily.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Remember to subset, taking just the final observation per customer with the final value for the flags.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 18:25:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-Lapsed-Customers/m-p/313553#M68152</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-11-22T18:25:44Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying Lapsed Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-Lapsed-Customers/m-p/313567#M68155</link>
      <description>&lt;P&gt;&lt;SPAN class="login-bold"&gt;Hi&amp;nbsp;&lt;A id="link_8" class="lia-link-navigation lia-page-link lia-user-name-link" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954" target="_self"&gt;Astounding&lt;/A&gt;&amp;nbsp;!!!! Thanks! last question. &amp;nbsp; The output dosent look right. &amp;nbsp; It doesnt look like its subsetting by mastr_customer_id and I'm getting negavtive numbers. &amp;nbsp;did I not modify the code correctly?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data days; &lt;BR /&gt;set have; &lt;BR /&gt; retain winback_:;&lt;BR /&gt;by mstr_customer_id transaction_date;&lt;BR /&gt;days_passed = dif(transaction_date);&lt;BR /&gt;if first.mstr_customer_id=0 then do;&lt;BR /&gt; if days_passed &amp;lt; 12 * 30 then do;&lt;BR /&gt; end;&lt;BR /&gt; else if days_passed &amp;lt; 24 * 30 then do;&lt;BR /&gt; winback_48='Y';&lt;BR /&gt; winback_36='Y';&lt;BR /&gt; winback_24='Y';&lt;BR /&gt; winback_12='Y';&lt;BR /&gt; end;&lt;BR /&gt; else if days_passed &amp;lt; 36 * 30 then do;&lt;BR /&gt; winback_24 = 'Y';&lt;BR /&gt; winback_36 = 'Y';&lt;BR /&gt; winback_48 = 'Y';&lt;BR /&gt; end;&lt;BR /&gt; if last.mstr_customer_id;&lt;BR /&gt;end;run; &lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 19:27:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-Lapsed-Customers/m-p/313567#M68155</guid>
      <dc:creator>Mgarret</dc:creator>
      <dc:date>2016-11-22T19:27:08Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying Lapsed Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-Lapsed-Customers/m-p/313568#M68156</link>
      <description>&lt;P&gt;So, I should say, its not resetting by ID.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 19:36:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-Lapsed-Customers/m-p/313568#M68156</guid>
      <dc:creator>Mgarret</dc:creator>
      <dc:date>2016-11-22T19:36:44Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying Lapsed Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-Lapsed-Customers/m-p/313570#M68158</link>
      <description>&lt;P&gt;Yes, it looks like you need to add the piece from an earlier post that sets the WINBACK variables to "N" as you begin a new customer.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 19:39:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-Lapsed-Customers/m-p/313570#M68158</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-11-22T19:39:23Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying Lapsed Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-Lapsed-Customers/m-p/313571#M68159</link>
      <description>&lt;P&gt;like this?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data days; &lt;BR /&gt;set dat.T_Hist_PFS; &lt;BR /&gt;by mstr_customer_id transaction_date;&lt;BR /&gt;days_passed = dif(transaction_date);&lt;BR /&gt;if first.mstr_customer_id then do;&lt;BR /&gt; winback_12='N';&lt;BR /&gt; winback_24='N';&lt;BR /&gt; winback_36='N';&lt;BR /&gt; winback_48='N';&lt;BR /&gt;end;&lt;BR /&gt;retain winback_:;&lt;BR /&gt; if days_passed &amp;lt; 12 * 30 then do;&lt;BR /&gt; end;&lt;BR /&gt; else if days_passed &amp;lt; 24 * 30 then do;&lt;BR /&gt; winback_48='Y';&lt;BR /&gt; winback_36='Y';&lt;BR /&gt; winback_24='Y';&lt;BR /&gt; winback_12='Y';&lt;BR /&gt; end;&lt;BR /&gt; else if days_passed &amp;lt; 36 * 30 then do;&lt;BR /&gt; winback_24 = 'Y';&lt;BR /&gt; winback_36 = 'Y';&lt;BR /&gt; winback_48 = 'Y';&lt;BR /&gt; end;&lt;BR /&gt;end; if last.mstr_customer_id;;run; &lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 19:41:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-Lapsed-Customers/m-p/313571#M68159</guid>
      <dc:creator>Mgarret</dc:creator>
      <dc:date>2016-11-22T19:41:57Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying Lapsed Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-Lapsed-Customers/m-p/313574#M68161</link>
      <description>&lt;P&gt;Very close.&amp;nbsp; The logic that sets WINBACK variables to "Y" should not be applied to every observation.&amp;nbsp; They only get applied when first.mstr_customer_id is equal to 0.&amp;nbsp; (The WINBACK to "Y" logic also needs to be expanded to cover all the possible categories.)&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 19:44:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-Lapsed-Customers/m-p/313574#M68161</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-11-22T19:44:33Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying Lapsed Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-Lapsed-Customers/m-p/313594#M68173</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think I am so close. &amp;nbsp;I'm still getting negative numbers .&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="571"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;&lt;STRONG&gt;MSTR_CUSTOMER_ID&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="114"&gt;&lt;STRONG&gt;transaction_date&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="89"&gt;&lt;STRONG&gt;days_passed&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="64"&gt;&lt;STRONG&gt;winback_12&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="80"&gt;&lt;STRONG&gt;winback_24&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="80"&gt;&lt;STRONG&gt;winback_36&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="80"&gt;&lt;STRONG&gt;winback_48&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&g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;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data days; &lt;BR /&gt;set have; &lt;BR /&gt;by mstr_customer_id ;&lt;BR /&gt;days_passed = dif(transaction_date);&lt;BR /&gt;if first.mstr_customer_id then do;&lt;BR /&gt;winback_12='N';&lt;BR /&gt;winback_24='N';&lt;BR /&gt;winback_36='N';&lt;BR /&gt;winback_48='N';&lt;BR /&gt;retain winback_:;&lt;BR /&gt;end;&lt;BR /&gt;if first.mstr_customer_id =0 then do;&lt;BR /&gt;if days_passed &amp;lt; 12 * 30 then do;&lt;BR /&gt;end;&lt;BR /&gt;else if days_passed &amp;lt; 24 * 30 then do;&lt;BR /&gt;winback_48='Y';&lt;BR /&gt;winback_36='Y';&lt;BR /&gt;winback_24='Y';&lt;BR /&gt;winback_12='Y';&lt;BR /&gt;end;&lt;BR /&gt;else if days_passed &amp;lt; 36 * 30 then do;&lt;BR /&gt;winback_24 = 'Y';&lt;BR /&gt;winback_36 = 'Y';&lt;BR /&gt;winback_48 = 'Y';&lt;BR /&gt;end;&lt;BR /&gt;else if days_passed &amp;lt; 48 * 30 then do;&lt;BR /&gt;winback_36 = 'Y';&lt;BR /&gt;winback_48 = 'Y';&lt;BR /&gt;end;&lt;BR /&gt;if last.mstr_customer_id; end;run;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 20:58:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-Lapsed-Customers/m-p/313594#M68173</guid>
      <dc:creator>Mgarret</dc:creator>
      <dc:date>2016-11-22T20:58:15Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying Lapsed Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-Lapsed-Customers/m-p/313605#M68176</link>
      <description>&lt;P&gt;Switch the order of the final two statements (the END and the subsetting IF).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would still be possible to get negative numbers for DAYS_PASSED, but only for customers that have a single observation.&amp;nbsp; The first calculation of DAYS_PASSED is always a customer's first purchase date minus the last purchase date for the previous customer.&amp;nbsp; That's why the WINBACK=Y logic gets nested so it executes when it is not the first observation for a customer.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 21:29:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-Lapsed-Customers/m-p/313605#M68176</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-11-22T21:29:46Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying Lapsed Customers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-Lapsed-Customers/m-p/313627#M68183</link>
      <description>&lt;P&gt;This program generates the variables LAPSED_12M, LAPSED_18M, LAPSED_24M, LAPSED36M to indicate whether the customer had at least one lapse of the corresponding length in months.&amp;nbsp; (LAPSED_xxM='Y' or 'N').&amp;nbsp; For only those with a "Y", the corresponding target variable (TARGET_12M, ....) is generated according to the rules you mention.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Notes for this untested program:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;I notice your date range goes up to 01nov2016, so I used 01nov2016 (as macrovar ENDDATE)&amp;nbsp;the end of the last "gap" for all customers.&amp;nbsp; (Say the customer buys something in early 2013, and nothing more.&amp;nbsp; Then knowing the enddate of 01nov2016 tells me the customer has a 12M gap, 18M, 24M, and 36M gap, and will have 4 target variables=0).&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;Because the example sheet states that anyone with FIRST purchase&amp;nbsp;xx or fewer months before the end_date cannot be said to have a lapse of size xx, they get a LAPSEC_xxM='N'.&amp;nbsp; (i.e. they started too late to have the corresponding gap).&amp;nbsp; To test for that condition there is an "if _n_=1 ..." do group that set corresponding cutdates for first purchase, which will be used against every first.customer_d record.&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;There is both a MERGE and a SET statement.&amp;nbsp; The merge (without a by) allows easy access to the gap size of current record to next record (firstobs=2).&amp;nbsp; The SET statement (with a by) is there just to establish first.customer_id and last.customer_id dummies.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Mark&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let begdate=01nov2012;
%let enddate=01nov2016;


data want (drop=I next_date)

  array lapse_length {4} _temporary_ (12,18,24,36);

  array cutdate{4} _temporary_;
  if _n_=1 then do I=1 to 4;
     cutdate{I}=intnx('month',"&amp;amp;enddate"d,-1*lapse_length{i},'s');
  end;

  merge have 
        have (firstobs=2 keep=customerid date 
              rename=(customer=next_id date=next_date));

  set have (keep=customer_id);
  by customer_id;

  array lapsed{4} $1 lapsed_12M lapsed_18M lapsed_24M lapsed_36M;
  array target{4}    target_12M target_18M target_24M target_36M;
  retain lapsed: target: ;

  if first.customer_id then do I=1 to 4; 
    if date&amp;gt;cutdate{I} then lapsed{I}='N';
    else do;
      lapsed{I}='Y';
      target{I}=0;   /* Start out assuming no subsequent purchase*/
    end;
  end;

  if last.customer_id then next_date="&amp;amp;enddate"d;
  monthsgap=intck('month',date,next_date,'continuous');

  do I=1 to 4 ;
    if lapsed{I}='Y' and monthsgap&amp;gt;lapse_length{I} and not(last.customer_id) 
     then target{I}=1;
  end;

  if last.customer_id;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2016 01:12:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-Lapsed-Customers/m-p/313627#M68183</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2016-11-23T01:12:31Z</dc:date>
    </item>
  </channel>
</rss>

