<?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: Time in between orders, Please Help. Thank you in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Time-in-between-orders-Please-Help-Thank-you/m-p/82710#M17832</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are on the right track with the commented lines, using first. logic will solve it. But you need to use NOT first.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 20 Mar 2013 11:42:40 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2013-03-20T11:42:40Z</dc:date>
    <item>
      <title>Time in between orders, Please Help. Thank you</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Time-in-between-orders-Please-Help-Thank-you/m-p/82709#M17831</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;STRONG style="color: #0000ff;"&gt;Hi All,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: #0000ff;"&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: #0000ff;"&gt;I have a transaction table that contains all the transactions (orders) made by ecah customer. I would like to calculate the difference between orders to detect when they start reducing their orders. I have run the code below, but it doesn't give what I need...For the first customer, the calculation is right but when I get to the second customer (the first row is wrong because it calculates the difference between the last date of the first customer and the first date of the second customer). How can I tell SAS, to stop at the last date of the first customer and start again at the first date of the first customer.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: #0000ff;"&gt;I have tried to use First function but it didon't work.. Your help wouldf be much appreciated. Many Thanks&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;DATA&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; MODELLING;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;SET&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; MODELLING; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: green; font-size: 10pt;"&gt;/*DIFFERENCE TIME BETWEEN ORDERS*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 10pt;"&gt;BY&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; SOLD_TO_ORG_ID DELIVERY_DATE;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: green; font-size: 10pt;"&gt;/*&amp;nbsp; IF FIRST.SOLD_TO_ORG_ID AND FIRST.DELIVERY_DATE THEN DO;*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp; LAG_TIME = LAG(DELIVERY_DATE);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp; DIF_TIME = DELIVERY_DATE - LAG_TIME;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp; PER_TIME_INCREASE =(DIF_TIME/LAG_TIME)*&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;100&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp; LAG_VALUE = LAG(TOTAL_SPEND);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp; DIF_VALUE = TOTAL_SPEND - LAG_VALUE;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&amp;nbsp; PER_VALUE_INCREASE =(DIF_VALUE/LAG_VALUE)*&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;100&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: green; font-size: 10pt;"&gt;/*&amp;nbsp; END;*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: green; font-size: 10pt;"&gt;/*&amp;nbsp; OUTPUT;*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;RUN&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Mar 2013 11:29:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Time-in-between-orders-Please-Help-Thank-you/m-p/82709#M17831</guid>
      <dc:creator>Question</dc:creator>
      <dc:date>2013-03-20T11:29:15Z</dc:date>
    </item>
    <item>
      <title>Re: Time in between orders, Please Help. Thank you</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Time-in-between-orders-Please-Help-Thank-you/m-p/82710#M17832</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are on the right track with the commented lines, using first. logic will solve it. But you need to use NOT first.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Mar 2013 11:42:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Time-in-between-orders-Please-Help-Thank-you/m-p/82710#M17832</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2013-03-20T11:42:40Z</dc:date>
    </item>
    <item>
      <title>Re: Time in between orders, Please Help. Thank you</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Time-in-between-orders-Please-Help-Thank-you/m-p/82711#M17833</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi LinusH,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your reply...when you say I need to use NOT first, where exactly in the program?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: green; font-size: 10pt;"&gt;IF FIRST.SOLD_TO_ORG_ID AND &lt;/SPAN&gt;&lt;STRONG style="color: red; font-size: 10pt; background: white; font-family: 'Courier New';"&gt;NOT &lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: green; font-size: 10pt;"&gt;FIRST.DELIVERY_DATE THEN DO;??&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Mar 2013 12:22:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Time-in-between-orders-Please-Help-Thank-you/m-p/82711#M17833</guid>
      <dc:creator>Question</dc:creator>
      <dc:date>2013-03-20T12:22:37Z</dc:date>
    </item>
    <item>
      <title>Re: Time in between orders, Please Help. Thank you</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Time-in-between-orders-Please-Help-Thank-you/m-p/82712#M17834</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Up to you to decide - for which rows do you want to calculate differences.&lt;/P&gt;&lt;P&gt;If only on the same day, you need to NOT both.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Mar 2013 13:46:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Time-in-between-orders-Please-Help-Thank-you/m-p/82712#M17834</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2013-03-20T13:46:27Z</dc:date>
    </item>
    <item>
      <title>Re: Time in between orders, Please Help. Thank you</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Time-in-between-orders-Please-Help-Thank-you/m-p/82713#M17835</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi LinusH,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to calculate the difference for every row per customer. For example if a customer has 10 transactions row, I would like to calculate the diff between 1st order and 2nd order, the diff between 2nd order and 3rd order, and difference between 3rd and 4th order so on...And when I get to the second customer, I would like to follow the same logic. Does it make sense?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Alice&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Mar 2013 14:39:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Time-in-between-orders-Please-Help-Thank-you/m-p/82713#M17835</guid>
      <dc:creator>Question</dc:creator>
      <dc:date>2013-03-20T14:39:19Z</dc:date>
    </item>
    <item>
      <title>Re: Time in between orders, Please Help. Thank you</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Time-in-between-orders-Please-Help-Thank-you/m-p/82714#M17836</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't understand the calculation of the increase/decrease, so I leave that to you. Taking the time-calculation: you divide the number of days between orders by the first date. That means that if they order exactly every 30 days you will see a decreasing result as the order date increases.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The calculation of the time between two purchases can be calculated as you do, but you have to make the calculated value missing every time you start with a new SOLD_TO_ORG_ID, like in the code below. By the way, you can use the DIF function to replace the combination of the LAG function and the subtraction.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data demo;&lt;/P&gt;&lt;P&gt;input SOLD_TO_ORG_ID DELIVERY_DATE : date. total_spend;&lt;/P&gt;&lt;P&gt;format delivery_date date.;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1 12APR12&amp;nbsp; 25&lt;/P&gt;&lt;P&gt;1 24apr12&amp;nbsp; 71&lt;/P&gt;&lt;P&gt;1 13may12&amp;nbsp; 321&lt;/P&gt;&lt;P&gt;1 04jun12&amp;nbsp; 59&lt;/P&gt;&lt;P&gt;1 15jul12&amp;nbsp; 77&lt;/P&gt;&lt;P&gt;2 19mar12&amp;nbsp; 91&lt;/P&gt;&lt;P&gt;2 23may12&amp;nbsp; 143&lt;/P&gt;&lt;P&gt;3 29mar12&amp;nbsp; 86&lt;/P&gt;&lt;P&gt;3 6apr12&amp;nbsp;&amp;nbsp; 47&lt;/P&gt;&lt;P&gt;3 17apr12&amp;nbsp; 66&lt;/P&gt;&lt;P&gt;3 16may12&amp;nbsp; 91&lt;/P&gt;&lt;P&gt;3 21jun12&amp;nbsp; 112&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data modeling;&lt;/P&gt;&lt;P&gt;set demo;&lt;/P&gt;&lt;P&gt;by SOLD_TO_ORG_ID DELIVERY_DATE ;&lt;/P&gt;&lt;P&gt;DIF_TIME = DIF(DELIVERY_DATE);&lt;/P&gt;&lt;P&gt;DIF_VALUE = dif(TOTAL_SPEND);&lt;/P&gt;&lt;P&gt;if first.sold_to_org_id then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; dif_time=.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; dif_value=.;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;ods listing;&lt;/P&gt;&lt;P&gt;options nocenter;&lt;/P&gt;&lt;P&gt;proc print;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Mar 2013 20:19:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Time-in-between-orders-Please-Help-Thank-you/m-p/82714#M17836</guid>
      <dc:creator>ErikT</dc:creator>
      <dc:date>2013-03-20T20:19:23Z</dc:date>
    </item>
    <item>
      <title>Re: Time in between orders, Please Help. Thank you</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Time-in-between-orders-Please-Help-Thank-you/m-p/82715#M17837</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can't have any opinions on what you are calculating.&lt;/P&gt;&lt;P&gt;But as you describe it, you shouldn't test on date, just sold_to_org_id.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Mar 2013 08:45:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Time-in-between-orders-Please-Help-Thank-you/m-p/82715#M17837</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2013-03-21T08:45:24Z</dc:date>
    </item>
    <item>
      <title>Re: Time in between orders, Please Help. Thank you</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Time-in-between-orders-Please-Help-Thank-you/m-p/82716#M17838</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi EricT,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many Thanks the code works perfectly...&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Alice&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Mar 2013 10:16:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Time-in-between-orders-Please-Help-Thank-you/m-p/82716#M17838</guid>
      <dc:creator>Question</dc:creator>
      <dc:date>2013-03-21T10:16:55Z</dc:date>
    </item>
  </channel>
</rss>

