<?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: How to extract a timestamp with one hour interval in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-timestamp-with-one-hour-interval/m-p/488352#M127274</link>
    <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;: not "at least one hour later", but as close as possible to one hour.&lt;BR /&gt;What to select, if after&lt;BR /&gt;188 18Jul17:18:10:00 83&lt;BR /&gt;Is&lt;BR /&gt;188 18Jul17:18:48:00 83?&lt;BR /&gt;Both are 19 minutes away from the perfect difference of one hour.</description>
    <pubDate>Mon, 20 Aug 2018 20:41:32 GMT</pubDate>
    <dc:creator>error_prone</dc:creator>
    <dc:date>2018-08-20T20:41:32Z</dc:date>
    <item>
      <title>How to extract a timestamp with one hour interval</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-timestamp-with-one-hour-interval/m-p/488300#M127261</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;My data is below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; temp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; ID TS HR;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;informat&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; TS &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New"&gt;datetime20.&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;format&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; TS &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New"&gt;datetime20.&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="Courier New"&gt;188 18Jul17:15:27:00 97&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;188 18Jul17:15:28:00 88&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;188 18Jul17:15:39:00 85&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;188 18Jul17:15:55:00 88&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;188 18Jul17:16:00:00 88&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;188 18Jul17:16:17:00 87&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;STRONG&gt;188 18Jul17:16:22:00 86&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;188 18Jul17:16:35:00 88&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;188 18Jul17:16:45:00 88&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;188 18Jul17:17:01:00 85&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="Courier New"&gt;188 18Jul17:17:29:00 83&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;188 18Jul17:17:31:00 84&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="Courier New"&gt;188 18Jul17:18:10:00 83&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="Courier New"&gt;188 18Jul17:19:00:00 82&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;STRONG&gt;188 18Jul17:21:00:00 81;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;FONT face="Courier New"&gt;run;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;what I need to do to is to extract HR at one hour interval (or close to one hour) from the first timestamp of each id. In the above data I have bold the timestamps I am interested in. How can I achieve this task. Thanks you all.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Aug 2018 18:06:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-timestamp-with-one-hour-interval/m-p/488300#M127261</guid>
      <dc:creator>AMFR</dc:creator>
      <dc:date>2018-08-20T18:06:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a timestamp with one hour interval</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-timestamp-with-one-hour-interval/m-p/488348#M127271</link>
      <description>&lt;P&gt;So as I see it, the logic is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You want the first observation for each ID output. Next, you want every observation where the following observation has a TS value that is at least one hour later than the last outputted observation, correct?&lt;/P&gt;</description>
      <pubDate>Mon, 20 Aug 2018 20:31:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-timestamp-with-one-hour-interval/m-p/488348#M127271</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-08-20T20:31:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a timestamp with one hour interval</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-timestamp-with-one-hour-interval/m-p/488352#M127274</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;: not "at least one hour later", but as close as possible to one hour.&lt;BR /&gt;What to select, if after&lt;BR /&gt;188 18Jul17:18:10:00 83&lt;BR /&gt;Is&lt;BR /&gt;188 18Jul17:18:48:00 83?&lt;BR /&gt;Both are 19 minutes away from the perfect difference of one hour.</description>
      <pubDate>Mon, 20 Aug 2018 20:41:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-timestamp-with-one-hour-interval/m-p/488352#M127274</guid>
      <dc:creator>error_prone</dc:creator>
      <dc:date>2018-08-20T20:41:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a timestamp with one hour interval</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-timestamp-with-one-hour-interval/m-p/488367#M127283</link>
      <description>It should be as close to one hour, either few minutes less or few minutes more to one hour. Answer for your question that it could be both.&lt;BR /&gt;Thanks</description>
      <pubDate>Mon, 20 Aug 2018 21:25:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-timestamp-with-one-hour-interval/m-p/488367#M127283</guid>
      <dc:creator>AMFR</dc:creator>
      <dc:date>2018-08-20T21:25:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a timestamp with one hour interval</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-timestamp-with-one-hour-interval/m-p/488369#M127285</link>
      <description>Draycut..yes I want the first observation for each of the ID and then TS should be as close to one hour, either few minutes less or more.&lt;BR /&gt;Thanks!</description>
      <pubDate>Mon, 20 Aug 2018 21:29:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-timestamp-with-one-hour-interval/m-p/488369#M127285</guid>
      <dc:creator>AMFR</dc:creator>
      <dc:date>2018-08-20T21:29:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a timestamp with one hour interval</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-timestamp-with-one-hour-interval/m-p/488376#M127289</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;has already asked what rule you want when there are ties.&amp;nbsp;&amp;nbsp; And what rule do you want when at the end of the id?&amp;nbsp; For instance if the reference time is&amp;nbsp;13:24&amp;nbsp; and you have the following complete time sequence for id 101&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;101 13:24&amp;nbsp;&amp;nbsp; kept&lt;/P&gt;
&lt;P&gt;101 13:40&lt;/P&gt;
&lt;P&gt;101 13:59&lt;/P&gt;
&lt;P&gt;101 14:20&amp;nbsp; kept&amp;nbsp;&amp;nbsp;&amp;nbsp; (closest to 14:24)&lt;/P&gt;
&lt;P&gt;101 14:50 (keep?)&lt;/P&gt;
&lt;P&gt;102 12:66&lt;/P&gt;
&lt;P&gt;... ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you keep the last 101 observation as closest toe 13:24 plus 2 hours?&amp;nbsp; the 13:24 and 14:20 will be kept,&amp;nbsp; but how close must the&amp;nbsp;5th observation be to the next target time (15:24) to be kept?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edited addition:&amp;nbsp; and did you want closest to one-hour after previous output, or closest to exact hour multiple after the first record?&lt;/P&gt;</description>
      <pubDate>Mon, 20 Aug 2018 21:56:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-timestamp-with-one-hour-interval/m-p/488376#M127289</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-08-20T21:56:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a timestamp with one hour interval</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-timestamp-with-one-hour-interval/m-p/488454#M127318</link>
      <description>&lt;P&gt;please try the below code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the min is the final dataset name which has the flag variable. if you subset min on flag=1 you will get the expected records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;hope it helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
input ID TS HR;
informat TS datetime20.;
format TS datetime20.;
datalines;
188 18Jul17:15:27:00 97
188 18Jul17:15:28:00 88
188 18Jul17:15:39:00 85
188 18Jul17:15:55:00 88
188 18Jul17:16:00:00 88
188 18Jul17:16:17:00 87
188 18Jul17:16:22:00 86
188 18Jul17:16:35:00 88
188 18Jul17:16:45:00 88
188 18Jul17:17:01:00 85
188 18Jul17:17:29:00 83
188 18Jul17:17:31:00 84
188 18Jul17:18:10:00 83
188 18Jul17:19:00:00 82
188 18Jul17:21:00:00 81
;
run;

proc sort data=temp;
by id ts;
run;

data temp2;
set temp;
by id ts;
retain ts2;
if first.id then ts2=ts;
hour=(intck('hour',ts2,ts)*60);
minutes=intck('minute',ts2,ts);
diff=abs(hour-minutes);
format TS2 datetime20.;
run;

proc sql;
create table min as select distinct a.id,a.ts,a.hr,a.hour,a.diff, case when a.diff ne 0 and a.diff=b.min then 1 else 0 end as flag from temp2 as a left join (select id,ts, min(diff) as min from temp2 group by id, hour) as b 
on a.id=b.id and a.diff=b.min and a.ts=b.ts;
quit;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Aug 2018 08:51:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-timestamp-with-one-hour-interval/m-p/488454#M127318</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2018-08-21T08:51:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a timestamp with one hour interval</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-timestamp-with-one-hour-interval/m-p/488488#M127334</link>
      <description>&lt;P&gt;Do you keep the last 101 observation as closest toe 13:24 plus 2 hours?&amp;nbsp; the 13:24 and 14:20 will be kept,&amp;nbsp; but how close must the&amp;nbsp;5th observation be to the next target time (15:24) to be kept? &lt;U&gt;Since 14:20 is almost an hour away from 13:24 so&amp;nbsp;I would like to keep it and drop 14;50 because I want one record for each hour. If there is any timestamp for the 15th hour which is close to 14:20 then it would be in otherwise 14:20 would be the last row for 101. I hope I make myself clear this time.&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edited addition:&amp;nbsp; and did you want closest to one-hour after previous output, or closest to exact hour multiple after the first record? I&lt;U&gt; am sorry I am not getting this question.&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help!&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 10:38:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-timestamp-with-one-hour-interval/m-p/488488#M127334</guid>
      <dc:creator>AMFR</dc:creator>
      <dc:date>2018-08-21T10:38:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a timestamp with one hour interval</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-timestamp-with-one-hour-interval/m-p/488492#M127335</link>
      <description>&lt;P&gt;Thank a lot for your help. Your codes work well for the first id of my dataset but not for others. SQL part is complicated for me so I have no idea how I can make it work for my whole dataset.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 10:56:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-timestamp-with-one-hour-interval/m-p/488492#M127335</guid>
      <dc:creator>AMFR</dc:creator>
      <dc:date>2018-08-21T10:56:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a timestamp with one hour interval</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-timestamp-with-one-hour-interval/m-p/488514#M127336</link>
      <description>&lt;P&gt;please try the below code which will output only the expected records, i wrote in datastep&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
input ID TS HR;
informat TS datetime20.;
format TS datetime20.;
datalines;
188 18Jul17:15:27:00 97
188 18Jul17:15:28:00 88
188 18Jul17:15:39:00 85
188 18Jul17:15:55:00 88
188 18Jul17:16:00:00 88
188 18Jul17:16:17:00 87
188 18Jul17:16:22:00 86
188 18Jul17:16:35:00 88
188 18Jul17:16:45:00 88
188 18Jul17:17:01:00 85
188 18Jul17:17:29:00 83
188 18Jul17:17:31:00 84
188 18Jul17:18:10:00 83
188 18Jul17:19:00:00 82
188 18Jul17:21:00:00 81
;
run;

proc sort data=temp;
by id ts;
run;

data temp2;
set temp;
by id ts;
retain ts2;
if first.id then ts2=ts;
hour=(intck('hour',ts2,ts)*60);
minutes=intck('minute',ts2,ts);
diff=abs(hour-minutes);
format TS2 datetime20.;
run;

proc sort data=temp2;
by id hour diff;
run;

data temp3;
set temp2;
by id hour diff;
if first.hour;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Aug 2018 12:17:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-timestamp-with-one-hour-interval/m-p/488514#M127336</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2018-08-21T12:17:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a timestamp with one hour interval</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-timestamp-with-one-hour-interval/m-p/488542#M127352</link>
      <description>&lt;P&gt;Thanks it worked and easy to understand as well. I really appreciate your help.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 13:17:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-a-timestamp-with-one-hour-interval/m-p/488542#M127352</guid>
      <dc:creator>AMFR</dc:creator>
      <dc:date>2018-08-21T13:17:26Z</dc:date>
    </item>
  </channel>
</rss>

