<?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 Test in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Test/m-p/691622#M210523</link>
    <description />
    <pubDate>Wed, 14 Oct 2020 22:06:55 GMT</pubDate>
    <dc:creator>Emma8</dc:creator>
    <dc:date>2020-10-14T22:06:55Z</dc:date>
    <item>
      <title>Test</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Test/m-p/691622#M210523</link>
      <description />
      <pubDate>Wed, 14 Oct 2020 22:06:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Test/m-p/691622#M210523</guid>
      <dc:creator>Emma8</dc:creator>
      <dc:date>2020-10-14T22:06:55Z</dc:date>
    </item>
    <item>
      <title>Re: Add New ID-s: if within one hour then the same IDs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Test/m-p/691637#M210534</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
	/* create newId and retain it */
	retain newid 1 ;
	format datetime datetime. ;
	infile want delimiter="," firstobs=2 ;
	input 
		ID			$
		datetime 	datetime16. 
		;
	/* Lag Function returns the prior value of datetime */
	lagdt=lag1(datetime) ;
	/* if current datetime-lagdt&amp;gt;60*60 (1 hour) then increment new id */
	if datetime-lagdt&amp;gt;60*60 then do ;
		newId+1 ;
	end ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Oct 2020 18:58:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Test/m-p/691637#M210534</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2020-10-14T18:58:48Z</dc:date>
    </item>
    <item>
      <title>Re: Add New ID-s: if within one hour then the same IDs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Test/m-p/691638#M210535</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
 infile cards dsd;
 input  ID $ Datetime :datetime20.;* NEW_ID;
 format datetime datetime20.;
 cards;
AAC56,25AUG20:02:00:00,1
AAC56,27AUG20:21:00:00,2
AAC56,31AUG20:10:30:00,3
AAC56,02SEP20:20:00:00,4
AAC56,29SEP20:21:43:00,5
AAC56,29SEP20:21:43:00,5
AAC56,29SEP20:22:03:00,5
;

data want;
 do until(last.id);
  set have;
  by id;
  if first.id or intck('min',_n_,datetime)&amp;gt;60 then do;
   new_id=sum(new_id,1);
   _n_=datetime;
  end;
  output;
 end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.WANT" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l header" scope="col"&gt;ID&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;Datetime&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;new_id&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;AAC56&lt;/TD&gt;
&lt;TD class="r data"&gt;25AUG2020:02:00:00&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;AAC56&lt;/TD&gt;
&lt;TD class="r data"&gt;27AUG2020:21:00:00&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;AAC56&lt;/TD&gt;
&lt;TD class="r data"&gt;31AUG2020:10:30:00&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;AAC56&lt;/TD&gt;
&lt;TD class="r data"&gt;02SEP2020:20:00:00&lt;/TD&gt;
&lt;TD class="r data"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;AAC56&lt;/TD&gt;
&lt;TD class="r data"&gt;29SEP2020:21:43:00&lt;/TD&gt;
&lt;TD class="r data"&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;AAC56&lt;/TD&gt;
&lt;TD class="r data"&gt;29SEP2020:21:43:00&lt;/TD&gt;
&lt;TD class="r data"&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;AAC56&lt;/TD&gt;
&lt;TD class="r data"&gt;29SEP2020:22:03:00&lt;/TD&gt;
&lt;TD class="r data"&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 14 Oct 2020 18:59:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Test/m-p/691638#M210535</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-10-14T18:59:36Z</dc:date>
    </item>
    <item>
      <title>Test</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Test/m-p/691722#M210578</link>
      <description />
      <pubDate>Fri, 16 Oct 2020 00:05:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Test/m-p/691722#M210578</guid>
      <dc:creator>Emma8</dc:creator>
      <dc:date>2020-10-16T00:05:12Z</dc:date>
    </item>
    <item>
      <title>Re: Add New ID-s: if within one hour then the same IDs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Test/m-p/691728#M210582</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/294547"&gt;@Emma8&lt;/a&gt;&amp;nbsp; My apologies for overlooking the question. Alright, I believe I understood&amp;nbsp;&lt;SPAN&gt;what you mean. Can you please clarify this one&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp;-&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;AAC56,25AUG20:&lt;FONT color="#FF0000"&gt;02:00:00,1&lt;/FONT&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;AAC56,27AUG20:&lt;FONT color="#FF0000"&gt;21:00:00,1&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;SPAN&gt;as the time difference seem&amp;nbsp;way off besides it's 2 days apart. So&amp;nbsp;wouldn't it be 1,2(new_id)?&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2020 03:09:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Test/m-p/691728#M210582</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-10-15T03:09:13Z</dc:date>
    </item>
    <item>
      <title>Re: Add New ID-s: if within one hour then the same IDs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Test/m-p/691729#M210583</link>
      <description>Sorry that should be 1 and 2</description>
      <pubDate>Thu, 15 Oct 2020 03:10:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Test/m-p/691729#M210583</guid>
      <dc:creator>Emma8</dc:creator>
      <dc:date>2020-10-15T03:10:29Z</dc:date>
    </item>
    <item>
      <title>Re: Add New ID-s: if within one hour then the same IDs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Test/m-p/691733#M210586</link>
      <description>&lt;P&gt;Hi again. Can you please revie&lt;SPAN&gt;w&lt;/SPAN&gt;&amp;nbsp; this one too-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;AAC58,29SEP20:&lt;STRONG&gt;16:00:00,2&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;AAC58,29SEP20:&lt;STRONG&gt;17:10:00,2&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Rather, Can you please revise the expected output for my correct reference please.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2020 03:17:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Test/m-p/691733#M210586</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-10-15T03:17:44Z</dc:date>
    </item>
    <item>
      <title>Test</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Test/m-p/691734#M210587</link>
      <description />
      <pubDate>Fri, 16 Oct 2020 00:10:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Test/m-p/691734#M210587</guid>
      <dc:creator>Emma8</dc:creator>
      <dc:date>2020-10-16T00:10:06Z</dc:date>
    </item>
    <item>
      <title>Re: Add New ID-s: if within one hour then the same IDs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Test/m-p/691738#M210591</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/294547"&gt;@Emma8&lt;/a&gt;&amp;nbsp; Thank you. Please try-&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards dsd;
input ID $ Datetime :datetime20.;* NEW_ID;
format datetime datetime20.;
cards;
AAC56,25AUG20:02:00:00,1
AAC56,27AUG20:21:00:00,2
AAC56,31AUG20:10:30:00,3
AAC56,02SEP20:20:00:00,4
AAC56,29SEP20:21:43:00,5
AAC56,29SEP20:21:43:00,5
AAC56,29SEP20:22:03:00,5
AAC56,29SEP20:23:03:00,5
AAC56,30SEP20:00:03:00,5
AAC56,30SEP20:01:03:00,5
AAC58,28SEP20:13:45:00,1
AAC58,29SEP20:15:00:00,2
AAC58,29SEP20:16:00:00,2
AAC58,29SEP20:16:00:00,2
AAC58,29SEP20:17:10:00,2
;


data want;
 do until(last.id);
  set have;
  by id;
  if first.id or intck('hour',_n_,datetime)&amp;gt;1 then new_id=sum(new_id,1);
  _n_=datetime;
  output;
 end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Fyi- The correction is-&lt;/P&gt;
&lt;P&gt;&lt;EM&gt; if first.id or intck('hour',_n_,datetime)&amp;gt;1 then new_id=sum(new_id,1);&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;_n_=datetime;&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2020 03:39:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Test/m-p/691738#M210591</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-10-15T03:39:43Z</dc:date>
    </item>
  </channel>
</rss>

