<?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 PLease help( inter sales times) in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/PLease-help-inter-sales-times/m-p/57201#M15964</link>
    <description>I need compute the time elapsed since the previous sale made by the same agent, whenever the previous sale was made on the same day. If Ithere is no previous sale on the same day, I need to compute the time since the start of work. The work begins at 9:00am. My data looks like as follows&lt;BR /&gt;
&lt;BR /&gt;
ID DATE                    SALES&lt;BR /&gt;
1  03Jan2008:10:50:30    40&lt;BR /&gt;
1  03Jan2008:10:59:01    30&lt;BR /&gt;
1  03Jan2008:11:04:02    40&lt;BR /&gt;
1  03Jan2008 :11:20:04   30&lt;BR /&gt;
1  03Feb2008 :09:05:40   30&lt;BR /&gt;
1  03Feb2008:11:06:05   30&lt;BR /&gt;
1  04Feb2008 :10:05:40   30&lt;BR /&gt;
1  05Feb2008:11:06:05   30&lt;BR /&gt;
2  03Jan2008 :09:04:06   40&lt;BR /&gt;
2  03Jan2008:10:05:08    30&lt;BR /&gt;
2  03Jan2008 :11:09:09   40&lt;BR /&gt;
2  03Jan2008:11:40:09    30&lt;BR /&gt;
2  03Jan2008 :12:45:09   40&lt;BR /&gt;
2  03Jan2008 :12:50:08   30&lt;BR /&gt;
2  03Feb2008:09:04:09    30&lt;BR /&gt;
2  03Feb2008 :09:56:08   30&lt;BR /&gt;
2  03Feb2008 :10:08:03   40&lt;BR /&gt;
2  04Feb2008 :11:08:09   30&lt;BR /&gt;
&lt;BR /&gt;
I need to have something like this.&lt;BR /&gt;
&lt;BR /&gt;
ID DATE                    SALES   inter_sales_time (minutes)&lt;BR /&gt;
1  03Jan2008:10:50:30    40        .&lt;BR /&gt;
1  03Jan2008:10:59:01    30        9&lt;BR /&gt;
1  03Jan2008:11:04:02    40         5&lt;BR /&gt;
1  03Jan2008 :11:20:04   30         16&lt;BR /&gt;
1  03Feb2008 :09:05:40   30         .&lt;BR /&gt;
1  03Feb2008:11:06:05   30         121&lt;BR /&gt;
1  04Feb2008 :10:05:40   30        65&lt;BR /&gt;
1  05Feb2008:11:06:05   30         126&lt;BR /&gt;
2  03Jan2008 :09:04:06   40          .&lt;BR /&gt;
2  03Jan2008:10:05:08    30         61&lt;BR /&gt;
2  03Feb2008 :10:08:03   40         68&lt;BR /&gt;
2  04Feb2008 :11:08:09   30         128&lt;BR /&gt;
&lt;BR /&gt;
I tried to create a variable say DATE1 = lag(DATE), and the substraye DATE1 from DATE, but it did not work. Please rescue me.</description>
    <pubDate>Mon, 15 Feb 2010 11:57:48 GMT</pubDate>
    <dc:creator>Statsconsultancy</dc:creator>
    <dc:date>2010-02-15T11:57:48Z</dc:date>
    <item>
      <title>PLease help( inter sales times)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PLease-help-inter-sales-times/m-p/57201#M15964</link>
      <description>I need compute the time elapsed since the previous sale made by the same agent, whenever the previous sale was made on the same day. If Ithere is no previous sale on the same day, I need to compute the time since the start of work. The work begins at 9:00am. My data looks like as follows&lt;BR /&gt;
&lt;BR /&gt;
ID DATE                    SALES&lt;BR /&gt;
1  03Jan2008:10:50:30    40&lt;BR /&gt;
1  03Jan2008:10:59:01    30&lt;BR /&gt;
1  03Jan2008:11:04:02    40&lt;BR /&gt;
1  03Jan2008 :11:20:04   30&lt;BR /&gt;
1  03Feb2008 :09:05:40   30&lt;BR /&gt;
1  03Feb2008:11:06:05   30&lt;BR /&gt;
1  04Feb2008 :10:05:40   30&lt;BR /&gt;
1  05Feb2008:11:06:05   30&lt;BR /&gt;
2  03Jan2008 :09:04:06   40&lt;BR /&gt;
2  03Jan2008:10:05:08    30&lt;BR /&gt;
2  03Jan2008 :11:09:09   40&lt;BR /&gt;
2  03Jan2008:11:40:09    30&lt;BR /&gt;
2  03Jan2008 :12:45:09   40&lt;BR /&gt;
2  03Jan2008 :12:50:08   30&lt;BR /&gt;
2  03Feb2008:09:04:09    30&lt;BR /&gt;
2  03Feb2008 :09:56:08   30&lt;BR /&gt;
2  03Feb2008 :10:08:03   40&lt;BR /&gt;
2  04Feb2008 :11:08:09   30&lt;BR /&gt;
&lt;BR /&gt;
I need to have something like this.&lt;BR /&gt;
&lt;BR /&gt;
ID DATE                    SALES   inter_sales_time (minutes)&lt;BR /&gt;
1  03Jan2008:10:50:30    40        .&lt;BR /&gt;
1  03Jan2008:10:59:01    30        9&lt;BR /&gt;
1  03Jan2008:11:04:02    40         5&lt;BR /&gt;
1  03Jan2008 :11:20:04   30         16&lt;BR /&gt;
1  03Feb2008 :09:05:40   30         .&lt;BR /&gt;
1  03Feb2008:11:06:05   30         121&lt;BR /&gt;
1  04Feb2008 :10:05:40   30        65&lt;BR /&gt;
1  05Feb2008:11:06:05   30         126&lt;BR /&gt;
2  03Jan2008 :09:04:06   40          .&lt;BR /&gt;
2  03Jan2008:10:05:08    30         61&lt;BR /&gt;
2  03Feb2008 :10:08:03   40         68&lt;BR /&gt;
2  04Feb2008 :11:08:09   30         128&lt;BR /&gt;
&lt;BR /&gt;
I tried to create a variable say DATE1 = lag(DATE), and the substraye DATE1 from DATE, but it did not work. Please rescue me.</description>
      <pubDate>Mon, 15 Feb 2010 11:57:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PLease-help-inter-sales-times/m-p/57201#M15964</guid>
      <dc:creator>Statsconsultancy</dc:creator>
      <dc:date>2010-02-15T11:57:48Z</dc:date>
    </item>
    <item>
      <title>Re: PLease help( inter sales times)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PLease-help-inter-sales-times/m-p/57202#M15965</link>
      <description>Using a SAS DATA step on your already sorted file, one technique is to have a SET and a corresponding BY statement to keep track of your FIRST.ID condition, and a RETAIN statement to track the prior observation (within the same ID group) and retain the DATEPART of the date/timestamp you have.&lt;BR /&gt;
&lt;BR /&gt;
With that processing, then you can do your computation/comparison for your retained date and the current observation's date-portion of the timestamp -- then output your resulting observation.  For your computed elapsed duration, use a SAS FORMAT statement to display the result in minutes format.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
Google advanced search argument, this topic/post:&lt;BR /&gt;
&lt;BR /&gt;
data step programming site:sas.com</description>
      <pubDate>Mon, 15 Feb 2010 13:45:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PLease-help-inter-sales-times/m-p/57202#M15965</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-02-15T13:45:14Z</dc:date>
    </item>
    <item>
      <title>Re: PLease help( inter sales times)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PLease-help-inter-sales-times/m-p/57203#M15966</link>
      <description>I would also go with Scott's suggestion.&lt;BR /&gt;
&lt;BR /&gt;
You just need to retain the previous SALES date/time and subtract it to the next element on the group (ID). Then reset the retained value to 9:00am.&lt;BR /&gt;
&lt;BR /&gt;
Like this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
data OUTDATA;&lt;BR /&gt;
length ELAPSED 8;&lt;BR /&gt;
format ELAPSED mmss5.;&lt;BR /&gt;
set INDATA;&lt;BR /&gt;
by ID; * assume INDATA is sorted by ID;&lt;BR /&gt;
drop _:;&lt;BR /&gt;
retain _AUX 8; * retain auxiliary var;&lt;BR /&gt;
if first.ID then _AUX=dhms(datepart(DATE),9,0,0); * reset auxiliary var;&lt;BR /&gt;
ELAPSED=DATE-_AUX; * calculate elapsed time;&lt;BR /&gt;
_AUX=DATE; * store current time for next iteration;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Cheers from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;</description>
      <pubDate>Mon, 15 Feb 2010 14:54:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PLease-help-inter-sales-times/m-p/57203#M15966</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2010-02-15T14:54:17Z</dc:date>
    </item>
  </channel>
</rss>

