<?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: Joining timesliced tables in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Joining-timesliced-tables/m-p/592195#M18109</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19791"&gt;@Filipvdr&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First - Please supply test data as code to create the data sets, so we know what we are dealing with and doesn't have to bother with actual values of date variables etc. and can work on a solution instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second - Will any given ID in table A have more than one FKEY, and/or more than one NAME, and could there be overlapping intervals for any given ID?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have an effecient macro to do the trick, but I would like to test it on your data before I post it, so I can get the macro options right according to your answers. Problem is the macro documentation is written in danish, so it will probably need some explanation too. I have some spare time this weekend....&lt;/P&gt;</description>
    <pubDate>Fri, 27 Sep 2019 15:22:49 GMT</pubDate>
    <dc:creator>ErikLund_Jensen</dc:creator>
    <dc:date>2019-09-27T15:22:49Z</dc:date>
    <item>
      <title>Joining timesliced tables</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Joining-timesliced-tables/m-p/592143#M18107</link>
      <description>&lt;P&gt;Hello guys..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm joining two timesliced tables but i'm struggling to get the correct output&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Table A:&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NAME&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; FKEY&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FROM&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TO&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PRODUCT_DESC&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BASKET&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1/1/2010&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1/1/2015&amp;nbsp; &amp;nbsp; &amp;nbsp; BASKETBALL&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BASKET&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2/1/2015&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 31/12/9999&amp;nbsp; BASKETBALL SPALDING&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PRODUCT2&amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1/1/2010&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 31/12/9999&amp;nbsp; TEMP&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;TABLE B (FKEY is ID here)&lt;/P&gt;
&lt;P&gt;FKEY&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FROM&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;TO&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;PRODUCT_CAT_DESCR&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1/1/2010&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;31/12/2013&amp;nbsp; &amp;nbsp;SPORTS EQUIPMENT&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1/1/2014&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;31/12/9999&amp;nbsp; &amp;nbsp;BASKETBALL EQUIPMENT&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm joining on the FKEY.&lt;/P&gt;
&lt;P&gt;As a result I would like to have 4 records for ID 1 with 4 different from/to's.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any idea's?&lt;/P&gt;</description>
      <pubDate>Fri, 27 Sep 2019 12:14:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Joining-timesliced-tables/m-p/592143#M18107</guid>
      <dc:creator>Filipvdr</dc:creator>
      <dc:date>2019-09-27T12:14:43Z</dc:date>
    </item>
    <item>
      <title>Re: Joining timesliced tables</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Joining-timesliced-tables/m-p/592193#M18108</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19791"&gt;@Filipvdr&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello guys..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm joining two timesliced tables but i'm struggling to get the correct output&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Table A:&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NAME&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; FKEY&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FROM&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TO&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PRODUCT_DESC&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BASKET&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1/1/2010&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1/1/2015&amp;nbsp; &amp;nbsp; &amp;nbsp; BASKETBALL&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BASKET&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2/1/2015&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 31/12/9999&amp;nbsp; BASKETBALL SPALDING&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PRODUCT2&amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1/1/2010&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 31/12/9999&amp;nbsp; TEMP&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;TABLE B (FKEY is ID here)&lt;/P&gt;
&lt;P&gt;FKEY&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FROM&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;TO&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;PRODUCT_CAT_DESCR&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1/1/2010&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;31/12/2013&amp;nbsp; &amp;nbsp;SPORTS EQUIPMENT&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1/1/2014&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;31/12/9999&amp;nbsp; &amp;nbsp;BASKETBALL EQUIPMENT&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm joining on the FKEY.&lt;/P&gt;
&lt;P&gt;As a result I would like to have 4 records for ID 1 with 4 different from/to's.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any idea's?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Can you show the code you attempted?&lt;/P&gt;
&lt;P&gt;And what you actually expect the output to look like for that example data? It is not at all clear what values might be needed in the result for NAME,&amp;nbsp;PRODUCT_DESC and &amp;nbsp;PRODUCT_CAT_DESCR in the results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And verify that the From and To are actually SAS date values and not character?&lt;/P&gt;</description>
      <pubDate>Fri, 27 Sep 2019 15:11:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Joining-timesliced-tables/m-p/592193#M18108</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-09-27T15:11:42Z</dc:date>
    </item>
    <item>
      <title>Re: Joining timesliced tables</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Joining-timesliced-tables/m-p/592195#M18109</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19791"&gt;@Filipvdr&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First - Please supply test data as code to create the data sets, so we know what we are dealing with and doesn't have to bother with actual values of date variables etc. and can work on a solution instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second - Will any given ID in table A have more than one FKEY, and/or more than one NAME, and could there be overlapping intervals for any given ID?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have an effecient macro to do the trick, but I would like to test it on your data before I post it, so I can get the macro options right according to your answers. Problem is the macro documentation is written in danish, so it will probably need some explanation too. I have some spare time this weekend....&lt;/P&gt;</description>
      <pubDate>Fri, 27 Sep 2019 15:22:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Joining-timesliced-tables/m-p/592195#M18109</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-09-27T15:22:49Z</dc:date>
    </item>
    <item>
      <title>Re: Joining timesliced tables</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Joining-timesliced-tables/m-p/592591#M18126</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tableA;
format from to date9. name PRODUCT_DESC $20.;
id = 1;
name = "BASKET";
FKEY = 2;
FROM = "01JAN2010"d;
TO = "01JAN2015"d;
PRODUCT_DESC = "BASKETBALL";
output;
id = 1;
name = "BASKET";
FKEY = 2;
FROM = "02JAN2015"d;
TO = "31DEC2099"d;
PRODUCT_DESC = "BASKETBALL SPALDING";
output;
id = 2;
name = "PRODUCT2";
FKEY = 3;
FROM = "01JAN2010"d;
TO = "31DEC2099"d;
PRODUCT_DESC = "TEMP";
output;
run;

data tableB;
format fromb tob date9.  PRODUCT_CAT_DESCR $20.;
fkey = 2;
fromb = "01JAN2010"d;
tob = "31DEC2013"d;
PRODUCT_CAT_DESCR = "SPORTS EQUIPMENT";
output;
fkey = 2;
fromb = "01JAN2014"d;
tob = "31DEC2099"d;
PRODUCT_CAT_DESCR = "BASKETBALL EQUIPMENT";
output;
run;

proc sql;
 create table records as select * from tablea,tableb where tablea.fkey=tableb.fkey
AND	(	tableb.fromb	BETWEEN	tablea.from AND tablea.to	
AND		tableb.tob	BETWEEN	tablea.from AND tablea.to	); 
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here is some code to generate the data. My last step to create a table records is trying to link both tables together. The output is only one row while my wanted output should be 4 rows, each for one timeslice which is available in the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="result.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/32826i4A9680599C4B0817/image-size/large?v=v2&amp;amp;px=999" role="button" title="result.PNG" alt="result.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;so the product basket now should have 3 rows, one for each timeslice&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Sep 2019 08:57:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Joining-timesliced-tables/m-p/592591#M18126</guid>
      <dc:creator>Filipvdr</dc:creator>
      <dc:date>2019-09-30T08:57:18Z</dc:date>
    </item>
    <item>
      <title>Re: Joining timesliced tables</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Joining-timesliced-tables/m-p/592634#M18127</link>
      <description>I found this paper and i will try it out: &lt;A href="https://pdfs.semanticscholar.org/dc07/8531d26794c3ca8a5079c8abc451eef4eedd.pdf" target="_blank"&gt;https://pdfs.semanticscholar.org/dc07/8531d26794c3ca8a5079c8abc451eef4eedd.pdf&lt;/A&gt;</description>
      <pubDate>Mon, 30 Sep 2019 11:48:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Joining-timesliced-tables/m-p/592634#M18127</guid>
      <dc:creator>Filipvdr</dc:creator>
      <dc:date>2019-09-30T11:48:16Z</dc:date>
    </item>
    <item>
      <title>Re: Joining timesliced tables</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Joining-timesliced-tables/m-p/593787#M18137</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19791"&gt;@Filipvdr&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I had a look at Jim Moon's paper, and I notice that it relies heavily on the &lt;EM&gt;between-operator&lt;/EM&gt;. It is a good approch to interval-joining small tables, but it is extremely slow when working with large tables, especially DBMS-tables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The macro I mentioned in my previous post (attached) is developed to overcome that and work fast with big tables. We use it in many production jobs, where interval joins with between used to run up to 2 hours, and now run in as many minutes instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Given your test input, this is the call:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%fletrensinterval(
	tableA, 
	tableB, 
	tableOUT, 
	unita=FKEY, datefirsta=FROM, datelasta=TO, 
	unitb=FKEY, datefirstb=fromb, datelastb=tob, 
	join=left, 
	byvarA=ID);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;TableA and TableB are the input tables, and tableOUT the resulting output tables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;unita, datefirsta and datelasta are the variables holding the key to join on and the from- and to-dates i TableA.&lt;/P&gt;
&lt;P&gt;unitb, datefirstb and datelastb are the variables holding the key to join on and the from- and to-dates i TableB.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Join=left preserves all keys/intervals in TableA, even if the key is not present in TableB, or (part of) an interval in TableA&amp;nbsp; is outside corresponding intervals in TableB&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ByvarA=ID is the name of a grouping variable in TableA (in this case ID), so separate joins are made for each ID value i A, if the join key (in this case FKEY) exists with more than one ID in TableA&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="result.gif" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/32930i30F18CBB1BF48CC5/image-size/large?v=v2&amp;amp;px=999" role="button" title="result.gif" alt="result.gif" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 15:48:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Joining-timesliced-tables/m-p/593787#M18137</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-10-03T15:48:56Z</dc:date>
    </item>
  </channel>
</rss>

