<?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: Combing data points based on time in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Combing-data-points-based-on-time/m-p/518336#M16091</link>
    <description>&lt;P&gt;No sorry, these wa just copy and paste from two different dataset &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I am looking for is that the Have1 dataset, which also have a varible called 'behaviour', which is the behaviour recorded during the time span, can be merged with the have2 and the behaviour recorded on a specific time in the have2 is merged to the right time period in have1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if we in have2 have a datapoint with a corresponding recorded behaviour/variable on: 11oct18:08:31:57 then this datapoint is merged into have1 on the same line as 11oct18:08:31:40&amp;nbsp; 11oct18:08:32:40&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 04 Dec 2018 09:56:05 GMT</pubDate>
    <dc:creator>PerNielsen</dc:creator>
    <dc:date>2018-12-04T09:56:05Z</dc:date>
    <item>
      <title>Combing data points based on time</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Combing-data-points-based-on-time/m-p/518329#M16089</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have a date set with datapoints based on one point per minute:&lt;/P&gt;
&lt;P&gt;Start&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End&lt;/P&gt;
&lt;P&gt;11OCT18:08:31:40&amp;nbsp;&amp;nbsp; 11OCT18:08:32:40&lt;/P&gt;
&lt;P&gt;11OCT18:08:32:40&amp;nbsp;&amp;nbsp; 11OCT18:08:33:40&lt;/P&gt;
&lt;P&gt;11OCT18:08:33:40&amp;nbsp;&amp;nbsp; 11OCT18:08:34:40&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and a direct observation of an animals behaviour within one of these time vindows.&lt;/P&gt;
&lt;TABLE width="215"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="95"&gt;Date&lt;/TD&gt;
&lt;TD width="120"&gt;Time&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="95"&gt;11-10-2018&lt;/TD&gt;
&lt;TD width="120"&gt;08:35:25&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="95"&gt;11-10-2018&lt;/TD&gt;
&lt;TD width="120"&gt;08:40:04&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="95"&gt;11-10-2018&lt;/TD&gt;
&lt;TD width="120"&gt;08:45:27&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do I merge these two dataset based on time? The datapoint from the direct observations need to be pared with the right timespan from the first data set.&lt;/P&gt;
&lt;P&gt;It is not a problem for me to work with the time and data data, either to split ithem up or combine them. Just need help on how to merge the data by datetime.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards,&lt;/P&gt;
&lt;P&gt;Per&lt;/P&gt;</description>
      <pubDate>Tue, 04 Dec 2018 09:14:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Combing-data-points-based-on-time/m-p/518329#M16089</guid>
      <dc:creator>PerNielsen</dc:creator>
      <dc:date>2018-12-04T09:14:23Z</dc:date>
    </item>
    <item>
      <title>Re: Combing data points based on time</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Combing-data-points-based-on-time/m-p/518332#M16090</link>
      <description>&lt;P&gt;Ok so your data looks like this, correct? Note that I have created a DateTime variable with the DHMS Function in the second data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not sure what you want the final data to look like. Can you post an example from the example data? The way I see it, none of the time values from have2 fall between any of the time spans in have1?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
input (Start End)(:datetime20.);
format Start End datetime20.;
datalines;
11OCT18:08:31:40 11OCT18:08:32:40
11OCT18:08:32:40 11OCT18:08:33:40
11OCT18:08:33:40 11OCT18:08:34:40
;

data have2;
input Date:ddmmyy10. Time:time8.;
format Date ddmmyy10. Time time8. DateTime datetime20.;
DateTime=dhms(Date, 0,0,Time);
datalines;
11-10-2018 08:35:25
11-10-2018 08:40:04
11-10-2018 08:45:27
;.&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Dec 2018 09:46:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Combing-data-points-based-on-time/m-p/518332#M16090</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-12-04T09:46:36Z</dc:date>
    </item>
    <item>
      <title>Re: Combing data points based on time</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Combing-data-points-based-on-time/m-p/518336#M16091</link>
      <description>&lt;P&gt;No sorry, these wa just copy and paste from two different dataset &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I am looking for is that the Have1 dataset, which also have a varible called 'behaviour', which is the behaviour recorded during the time span, can be merged with the have2 and the behaviour recorded on a specific time in the have2 is merged to the right time period in have1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if we in have2 have a datapoint with a corresponding recorded behaviour/variable on: 11oct18:08:31:57 then this datapoint is merged into have1 on the same line as 11oct18:08:31:40&amp;nbsp; 11oct18:08:32:40&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Dec 2018 09:56:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Combing-data-points-based-on-time/m-p/518336#M16091</guid>
      <dc:creator>PerNielsen</dc:creator>
      <dc:date>2018-12-04T09:56:05Z</dc:date>
    </item>
    <item>
      <title>Re: Combing data points based on time</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Combing-data-points-based-on-time/m-p/518341#M16092</link>
      <description>&lt;P&gt;Ah ok &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Shouldn't be too complicated. Last question. Do both data sets have a behaviour variable? And should both behaviour varaibles be in your desired data set, provided the time span fits?&lt;/P&gt;</description>
      <pubDate>Tue, 04 Dec 2018 10:08:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Combing-data-points-based-on-time/m-p/518341#M16092</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-12-04T10:08:13Z</dc:date>
    </item>
    <item>
      <title>Re: Combing data points based on time</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Combing-data-points-based-on-time/m-p/518343#M16093</link>
      <description>&lt;P&gt;I think this gives you what you want. It is not the most efficient, but if you do not have too many records, it will do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let me know if it meets your needs &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
input (Start End)(:datetime20.) behaviour $20.;
format Start End datetime20.;
datalines;
11OCT18:08:31:40 11OCT18:08:32:40 Bad
11OCT18:08:32:40 11OCT18:08:33:40 Good
11OCT18:08:33:40 11OCT18:08:34:40 Bad
;

data have2;
input Date:ddmmyy10. Time:time8. behaviour $20.;
format Date ddmmyy10. Time time8. DateTime datetime20.;
DateTime=dhms(Date, 0,0,Time);
datalines;
11-10-2018 08:35:25 Bad
11-10-2018 08:40:04 Good
11-10-2018 08:45:27 Bad
11-10-2018 08:31:57 Good
;

proc sql;
   create table want as
   select have1.*
         ,have2.DateTime as DateTime
         ,have2.Behaviour as Behaviour2
   from have1 left join have2
   on have2.DateTime between Start and End;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Dec 2018 10:24:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Combing-data-points-based-on-time/m-p/518343#M16093</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-12-04T10:24:46Z</dc:date>
    </item>
    <item>
      <title>Re: Combing data points based on time</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Combing-data-points-based-on-time/m-p/518346#M16094</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input date :ddmmyy10. time : time8.;
maindate=dhms(date,hour(time),minute(time),second(time));
format date date9. time time8. maindate datetime18.;
cards;
11-10-2018 08:35:25
11-10-2018 08:40:04
11-10-2018 08:45:27
;

data have2;
input Start: datetime16. End : datetime16.;
format start datetime18. end datetime18.;
cards;
11OCT18:08:31:40   11OCT18:08:32:40
11OCT18:08:32:40   11OCT18:08:33:40
11OCT18:08:33:40   11OCT18:08:34:40
;

proc sql;
create table want as select a.maindate, b.start, b.end from have as a left join have2 as b on b.start&amp;lt;=a.maindate&amp;lt;=b.end;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Dec 2018 10:31:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Combing-data-points-based-on-time/m-p/518346#M16094</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2018-12-04T10:31:09Z</dc:date>
    </item>
    <item>
      <title>Re: Combing data points based on time</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Combing-data-points-based-on-time/m-p/518719#M16105</link>
      <description>&lt;P&gt;Just realised that I also need to combine by animal, have observed more than one cow and all data include more than one cow...&lt;/P&gt;
&lt;P&gt;This is have2, timestamp is formatted at datetime20. in my sas dataset.&lt;/P&gt;
&lt;TABLE width="271"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="79"&gt;Timestamp&lt;/TD&gt;
&lt;TD width="64"&gt;Cow_ID&lt;/TD&gt;
&lt;TD width="64"&gt;State&lt;/TD&gt;
&lt;TD width="64"&gt;Zone&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1539246925&lt;/TD&gt;
&lt;TD&gt;6300&lt;/TD&gt;
&lt;TD&gt;Standing&lt;/TD&gt;
&lt;TD&gt;Feeding&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1539247204&lt;/TD&gt;
&lt;TD&gt;6300&lt;/TD&gt;
&lt;TD&gt;Eating&lt;/TD&gt;
&lt;TD&gt;Feeding&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1539247527&lt;/TD&gt;
&lt;TD&gt;6300&lt;/TD&gt;
&lt;TD&gt;Eating&lt;/TD&gt;
&lt;TD&gt;Feeding&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1539247812&lt;/TD&gt;
&lt;TD&gt;6300&lt;/TD&gt;
&lt;TD&gt;Eating&lt;/TD&gt;
&lt;TD&gt;Feeding&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;have2&lt;/P&gt;
&lt;TABLE width="298"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="117"&gt;start_time&lt;/TD&gt;
&lt;TD width="117"&gt;end_time&lt;/TD&gt;
&lt;TD width="64"&gt;cow_id&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;11OCT18:08:31:40&lt;/TD&gt;
&lt;TD&gt;11OCT18:08:32:40&lt;/TD&gt;
&lt;TD&gt;6300&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;11OCT18:08:32:40&lt;/TD&gt;
&lt;TD&gt;11OCT18:08:33:40&lt;/TD&gt;
&lt;TD&gt;6300&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;11OCT18:08:32:40&lt;/TD&gt;
&lt;TD&gt;11OCT18:08:33:40&lt;/TD&gt;
&lt;TD&gt;6300&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;11OCT18:08:33:40&lt;/TD&gt;
&lt;TD&gt;11OCT18:08:34:40&lt;/TD&gt;
&lt;TD&gt;6300&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;11OCT18:08:33:40&lt;/TD&gt;
&lt;TD&gt;11OCT18:08:34:40&lt;/TD&gt;
&lt;TD&gt;6300&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;so not only do I need to merge these two files by time but also by cow_id.&lt;/P&gt;
&lt;P&gt;There is a lot more variable in both files, but as I can see from what I can do in the in program you wrote, it does not really matter since they are all included&lt;/P&gt;</description>
      <pubDate>Wed, 05 Dec 2018 10:19:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Combing-data-points-based-on-time/m-p/518719#M16105</guid>
      <dc:creator>PerNielsen</dc:creator>
      <dc:date>2018-12-05T10:19:32Z</dc:date>
    </item>
    <item>
      <title>Re: Combing data points based on time</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Combing-data-points-based-on-time/m-p/518724#M16106</link>
      <description>&lt;P&gt;please try this code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the cow_id will be missing in the want dataset since the cow_id date range does not match with the start and end date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input maindate  cow_id state $ zone$;
format maindate datetime18.;
cards;
1539246925 6300 Standing Feeding
1539247204 6300 Eating Feeding
1539247527 6300 Eating Feeding
1539247812 6300 Eating Feeding
;

data have2;
input Start: datetime16. End : datetime16.;
format start datetime18. end datetime18.;
cards;
11OCT18:08:31:40   11OCT18:08:32:40
11OCT18:08:32:40   11OCT18:08:33:40
11OCT18:08:33:40   11OCT18:08:34:40
;

proc sql;
create table want as select a.*, b.start, b.end from have2 as b left join have as a on b.start&amp;lt;=a.maindate&amp;lt;=b.end;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Dec 2018 10:46:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Combing-data-points-based-on-time/m-p/518724#M16106</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2018-12-05T10:46:18Z</dc:date>
    </item>
  </channel>
</rss>

