<?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: find out two times for which the difference between them larger &amp;gt;30 days in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/find-out-two-times-for-which-the-difference-between-them-larger/m-p/277346#M55670</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I just realized that I actually want the first and last order_time within each time frame without gap, say,&lt;/P&gt;
&lt;P&gt;t1 .... t2&amp;nbsp; -- over 30day gap -- t3 ... t4&amp;nbsp; -- over 30day gap -- t5 ... t6 -- over 30day gap -- t7...t8 ........&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want the pairs of (t1, t2), (t3, t4), (t5, t6). The above codes are to get the pairs (t2, t3) (t4, t5), etc.&lt;/P&gt;
&lt;P&gt;This seems more difficult. Can any one help?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 14 Jun 2016 18:54:02 GMT</pubDate>
    <dc:creator>fengyuwuzu</dc:creator>
    <dc:date>2016-06-14T18:54:02Z</dc:date>
    <item>
      <title>find out two times for which the difference between them larger &gt;30 days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-out-two-times-for-which-the-difference-between-them-larger/m-p/277289#M55656</link>
      <description>&lt;P&gt;My data has ID and order_time, and I want to find out the order_time and the last order_time, the difference between which is &amp;gt; 30days.&lt;/P&gt;
&lt;P&gt;My best code is as below; I wonder if there is a simpler way to do it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have ;
by ID order_time;
	time1=lag(order_time);
	dif_time=dif(order_time)/3600/24; /* convert seconds to days */
	time2=order_time;
	if first.ID then do;
	time1=.;
	dif_time=.;
	time2=.;
    end;
format time1 datetime.;
format time2 datetime.;
if dif_time &amp;gt;30; /* choose  gaps &amp;gt;30 days */
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Jun 2016 16:03:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-out-two-times-for-which-the-difference-between-them-larger/m-p/277289#M55656</guid>
      <dc:creator>fengyuwuzu</dc:creator>
      <dc:date>2016-06-14T16:03:05Z</dc:date>
    </item>
    <item>
      <title>Re: find out two times for which the difference between them larger &gt;30 days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-out-two-times-for-which-the-difference-between-them-larger/m-p/277315#M55660</link>
      <description>&lt;P&gt;Simpler code with DO until()&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
do until(last.id);
	set have ; by ID;
	if first.id then first_order_time = order_time;
	id last.id then do;
		last_order_time = order_time;
		if intck("DTDAY", first_order_time, last_order_time, "CONTINUOUS") &amp;gt; 30 then output; 
		end;
format first_order_time last_order_time datetime.;
keep ID first_order_time last_order_time;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(untested)&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jun 2016 17:37:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-out-two-times-for-which-the-difference-between-them-larger/m-p/277315#M55660</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-06-14T17:37:52Z</dc:date>
    </item>
    <item>
      <title>Re: find out two times for which the difference between them larger &gt;30 days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-out-two-times-for-which-the-difference-between-them-larger/m-p/277340#M55666</link>
      <description>&lt;P&gt;Thank you. This works (one "if" is mis-spelled as "id", and one "end" is missing).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jun 2016 18:27:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-out-two-times-for-which-the-difference-between-them-larger/m-p/277340#M55666</guid>
      <dc:creator>fengyuwuzu</dc:creator>
      <dc:date>2016-06-14T18:27:17Z</dc:date>
    </item>
    <item>
      <title>Re: find out two times for which the difference between them larger &gt;30 days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-out-two-times-for-which-the-difference-between-them-larger/m-p/277346#M55670</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I just realized that I actually want the first and last order_time within each time frame without gap, say,&lt;/P&gt;
&lt;P&gt;t1 .... t2&amp;nbsp; -- over 30day gap -- t3 ... t4&amp;nbsp; -- over 30day gap -- t5 ... t6 -- over 30day gap -- t7...t8 ........&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want the pairs of (t1, t2), (t3, t4), (t5, t6). The above codes are to get the pairs (t2, t3) (t4, t5), etc.&lt;/P&gt;
&lt;P&gt;This seems more difficult. Can any one help?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jun 2016 18:54:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-out-two-times-for-which-the-difference-between-them-larger/m-p/277346#M55670</guid>
      <dc:creator>fengyuwuzu</dc:creator>
      <dc:date>2016-06-14T18:54:02Z</dc:date>
    </item>
    <item>
      <title>Re: find out two times for which the difference between them larger &gt;30 days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-out-two-times-for-which-the-difference-between-them-larger/m-p/277429#M55702</link>
      <description>&lt;P&gt;I think it can be done in two steps:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
set have; by id;
prevTime = lag(order_time);
if first.id then frame + 1;
else frame + intck("DTDAY", prevTime, order_time, "CONTINUOUS") &amp;gt; 30;
drop prevTime;
run;

data want;
do until(last.frame);
	set temp; by ID frame;
	if first.frame then first_order_time = order_time;
	if last.frame then last_order_time = order_time;
	end;
if first_order_time &amp;lt; last_order_time;
format first_order_time last_order_time datetime.;
keep ID first_order_time last_order_time;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(untested)&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2016 02:38:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-out-two-times-for-which-the-difference-between-them-larger/m-p/277429#M55702</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-06-15T02:38:29Z</dc:date>
    </item>
    <item>
      <title>Re: find out two times for which the difference between them larger &gt;30 days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-out-two-times-for-which-the-difference-between-them-larger/m-p/277956#M55878</link>
      <description>&lt;P&gt;Thank you, PGSTATS.&lt;/P&gt;
&lt;P&gt;It works with minor revsision: The following line needs to be changed&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;first&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;id&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; frame &lt;SPAN class="token operator"&gt;+&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;first&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;id&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; frame &lt;SPAN class="token operator"&gt;=0&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;otherwise frame sum accross all IDs; by reset to 0 for each new ID, it only sum within the same ID. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much for all your helsps.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2016 16:19:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-out-two-times-for-which-the-difference-between-them-larger/m-p/277956#M55878</guid>
      <dc:creator>fengyuwuzu</dc:creator>
      <dc:date>2016-06-16T16:19:27Z</dc:date>
    </item>
  </channel>
</rss>

