<?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: complex join with large tables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/complex-join-with-large-tables/m-p/110990#M23007</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A small example (table A and B before and table A after) would greatly help understand what you want.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 03 Sep 2012 13:30:05 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2012-09-03T13:30:05Z</dc:date>
    <item>
      <title>complex join with large tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/complex-join-with-large-tables/m-p/110989#M23006</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi everybody,&lt;/P&gt;&lt;P&gt;I need to perform a join between a main table with about 200 millions records (call it table A) and a table with about 3 millions records (table B). &lt;/P&gt;&lt;P&gt;both have repeated observations (monthly)&amp;nbsp; per subject within a year.&lt;/P&gt;&lt;P&gt;the merging key is composed by two variables that identify the subject (X, Y) and the month (M).&lt;/P&gt;&lt;P&gt;The resulting table should be composed of all records of table A plus the records not found in table A but only in B. For these last type of records I would like to assign some of the variables from the closest month (if any) according to the following rule:&lt;/P&gt;&lt;P&gt;the closest previous month or, if there are no record from the past, the closest subsequent month.&lt;/P&gt;&lt;P&gt;both tables resides on a Oracle DBMS and are indexed by the variables (X,Y,M), although I can download them to use in sas &lt;/P&gt;&lt;P&gt;I would appreciate any suggestions. If hash objects are involved I would need some more explanations as I am quite new to this world. However I'm willing to learn about them.&lt;/P&gt;&lt;P&gt;Thank you very much in advance&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;/P&gt;&lt;DIV id="gmBabelFish" style="border: 1px solid black; display: none; position: absolute; background-color: #a8ecff; padding: 2px; font-size: 12px; color: black; text-align: left; z-index: 100;"&gt;&lt;DIV style="border-bottom: 1px dotted black; padding-bottom: 2px; padding-top: 2px;"&gt;&lt;SPAN class="gmBabelMousishToolBar" style="cursor: pointer;" title="Close babel mousish"&gt;x&lt;/SPAN&gt;&lt;SPAN class="gmBabelMousishToolBar" style="cursor: pointer;" title="Configure languange"&gt;c&lt;/SPAN&gt;&lt;SPAN class="gmBabelMousishToolBar" style="cursor: default;" title="From English To Italian"&gt;en &amp;gt; it&lt;/SPAN&gt;&lt;IMG align="middle" src="https://communities.sas.com/" style="cursor: pointer;" title="click to translate" /&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Sep 2012 13:19:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/complex-join-with-large-tables/m-p/110989#M23006</guid>
      <dc:creator>ciro</dc:creator>
      <dc:date>2012-09-03T13:19:00Z</dc:date>
    </item>
    <item>
      <title>Re: complex join with large tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/complex-join-with-large-tables/m-p/110990#M23007</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A small example (table A and B before and table A after) would greatly help understand what you want.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Sep 2012 13:30:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/complex-join-with-large-tables/m-p/110990#M23007</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2012-09-03T13:30:05Z</dc:date>
    </item>
    <item>
      <title>Re: complex join with large tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/complex-join-with-large-tables/m-p/110991#M23008</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;SAS is really needed? If both tables reside into ORACLE, have you considered running the query there?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you do need the result in SAS I would br advisable to perform SQL pass-trough (inside ORALCE) and just retrieve the result.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers from Portugal.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Sep 2012 13:52:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/complex-join-with-large-tables/m-p/110991#M23008</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2012-09-03T13:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: complex join with large tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/complex-join-with-large-tables/m-p/110992#M23009</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;From a performance view, writing a pass-thru SQL could be wise.&lt;/P&gt;&lt;P&gt;But by the description of the exception handling (only from table B, then...) could be quite intriguing to write in pure SQL. Language wise, I think the data step is preferable here. maybe hash, or last.-processing after a full join.&lt;/P&gt;&lt;P&gt;Is this an operations that should be done often, or is it an ad-hoc situation?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Sep 2012 14:32:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/complex-join-with-large-tables/m-p/110992#M23009</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2012-09-03T14:32:17Z</dc:date>
    </item>
    <item>
      <title>Re: complex join with large tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/complex-join-with-large-tables/m-p/110993#M23010</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;From a quick look to ORACLE's own documentation this should do the trick for exception handling:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 10pt; font-family: 'Courier New';"&gt;select&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt; * from B &lt;STRONG&gt;where not exists&lt;/STRONG&gt; (&lt;STRONG&gt;select&lt;/STRONG&gt; * from A &lt;STRONG&gt;where&lt;/STRONG&gt; A.X=B.X and A.Y=B.Y AND A.M=B.M)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This would return B except A by (X,Y,M).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then it's just a matter of joining A back to the result, say with the UNION or if you need the whole thing in SAS bring back those two pieces of data and append them together.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With that volume of data and for most case, I guess it's better to let the DBMS handle it's own data and just transfer the results.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you choose the "Hash/Merge way" be cautious with multiple keys on both sides (N to N relations).&lt;/P&gt;&lt;P&gt;Merge won't handle this on a traditional way, same for Hash bellow SAS v9.2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers from Portugal.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Sep 2012 15:22:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/complex-join-with-large-tables/m-p/110993#M23010</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2012-09-03T15:22:06Z</dc:date>
    </item>
    <item>
      <title>Re: complex join with large tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/complex-join-with-large-tables/m-p/110994#M23011</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thank you to all for the answers.&lt;/P&gt;&lt;P&gt;following is an example of what i need.&lt;/P&gt;&lt;P&gt;as for the operations it is not to be performed often, so I can afford to bring the data soon in&amp;nbsp; sas and then perform the join.&lt;/P&gt;&lt;P&gt;another thing that i forgot and is not in the example is that I can have multiple records for the key (X,Y,M) in dataset A, though not frequently. In that case let's suppose I need variables from one record randomly for the moment &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data A;&lt;/P&gt;&lt;P&gt;input X $ Y $ M Z $ var1 ;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;A 0001 1 P 10&lt;/P&gt;&lt;P&gt;A 0001 2 P 11&lt;/P&gt;&lt;P&gt;A 0001 3 P 12&lt;/P&gt;&lt;P&gt;A 0001 4 P 13&lt;/P&gt;&lt;P&gt;A 0001 8 P 17&lt;/P&gt;&lt;P&gt;A 0001 9 P 18&lt;/P&gt;&lt;P&gt;A 0001 10 P 20&lt;/P&gt;&lt;P&gt;A 0002 4 P 21&lt;/P&gt;&lt;P&gt;A 0002 5 P 23&lt;/P&gt;&lt;P&gt;A 0002 6 P 25&lt;/P&gt;&lt;P&gt;A 0002 7 P 27&lt;/P&gt;&lt;P&gt;A 0002 8 P 27&lt;/P&gt;&lt;P&gt;A 0002 9 P 20&lt;/P&gt;&lt;P&gt;A 0002 10 P 15&lt;/P&gt;&lt;P&gt;A 0002 11 P 14&lt;/P&gt;&lt;P&gt;A 0002 12 P 12&lt;/P&gt;&lt;P&gt;B 0041 1 F 18&lt;/P&gt;&lt;P&gt;B 0041 2 F 18&lt;/P&gt;&lt;P&gt;B 0041 3 F 19&lt;/P&gt;&lt;P&gt;B 0041 4 F 20&lt;/P&gt;&lt;P&gt;B 0041 5 F 21&lt;/P&gt;&lt;P&gt;B 0041 6 F 17&lt;/P&gt;&lt;P&gt;B 0041 7 F 17&lt;/P&gt;&lt;P&gt;B 0041 8 F 17&lt;/P&gt;&lt;P&gt;B 0041 9 F 20&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data B;&lt;/P&gt;&lt;P&gt;input X $ Y $ M S $ var2 ;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;A 0001 5 E 4&lt;/P&gt;&lt;P&gt;A 0001 6 E 4&lt;/P&gt;&lt;P&gt;A 0001 7 E 6&lt;/P&gt;&lt;P&gt;A 0001 10 O 2&lt;/P&gt;&lt;P&gt;A 0001 12 E 6&lt;/P&gt;&lt;P&gt;A 0002 3 E 4&lt;/P&gt;&lt;P&gt;B 0041 8 O 5&lt;/P&gt;&lt;P&gt;B 0041 9 O 6&lt;/P&gt;&lt;P&gt;B 0041 10 E 6&lt;/P&gt;&lt;P&gt;B 0041 11 E 6&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data A_after;&lt;/P&gt;&lt;P&gt;infile datalines delimiter=',';&lt;/P&gt;&lt;P&gt;input X $ Y $ M Z $ var1 S $ var2;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;A,0001,1,P,10, ,&lt;/P&gt;&lt;P&gt;A,0001,2,P,11, ,&lt;/P&gt;&lt;P&gt;A,0001,3,P,12, ,&lt;/P&gt;&lt;P&gt;A,0001,4,P,13, ,&lt;/P&gt;&lt;P&gt;A,0001,5,P,13,E,4&lt;/P&gt;&lt;P&gt;A,0001,6,P,13,E,4&lt;/P&gt;&lt;P&gt;A,0001,7,P,13,E,6&lt;/P&gt;&lt;P&gt;A,0001,8,P,17, ,&lt;/P&gt;&lt;P&gt;A,0001,9,P,18, ,&lt;/P&gt;&lt;P&gt;A,0001,10,P,20,O,2&lt;/P&gt;&lt;P&gt;A,0001,12,P,20,E,6&lt;/P&gt;&lt;P&gt;A,0002,3,P,21,E,4&lt;/P&gt;&lt;P&gt;A,0002,4,P,21, ,&lt;/P&gt;&lt;P&gt;A,0002,5,P,23, ,&lt;/P&gt;&lt;P&gt;A,0002,6,P,25, ,&lt;/P&gt;&lt;P&gt;A,0002,7,P,27, ,&lt;/P&gt;&lt;P&gt;A,0002,8,P,27, ,&lt;/P&gt;&lt;P&gt;A,0002,9,P,20, ,&lt;/P&gt;&lt;P&gt;A,0002,10,P,15, ,&lt;/P&gt;&lt;P&gt;A,0002,11,P,14, ,&lt;/P&gt;&lt;P&gt;A,0002,12,P,12, ,&lt;/P&gt;&lt;P&gt;B,0041,1,F,18, ,&lt;/P&gt;&lt;P&gt;B,0041,2,F,18, ,&lt;/P&gt;&lt;P&gt;B,0041,3,F,19, ,&lt;/P&gt;&lt;P&gt;B,0041,4,F,20, ,&lt;/P&gt;&lt;P&gt;B,0041,5,F,21, ,&lt;/P&gt;&lt;P&gt;B,0041,6,F,17, ,&lt;/P&gt;&lt;P&gt;B,0041,7,F,17, ,&lt;/P&gt;&lt;P&gt;B,0041,8,F,17,O,5&lt;/P&gt;&lt;P&gt;B,0041,9,F,20,O,6&lt;/P&gt;&lt;P&gt;B,0041,10,F,20,E,6&lt;/P&gt;&lt;P&gt;B,0041,11,F,20,E,6&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;DIV id="gmBabelFish" style="border: 1px solid black; display: none; position: absolute; background-color: #a8ecff; padding: 2px; font-size: 12px; color: black; text-align: left; z-index: 100;"&gt;&lt;DIV style="border-bottom: 1px dotted black; padding-bottom: 2px; padding-top: 2px;"&gt;&lt;SPAN class="gmBabelMousishToolBar" style="cursor: pointer;" title="Close babel mousish"&gt;x&lt;/SPAN&gt;&lt;SPAN class="gmBabelMousishToolBar" style="cursor: pointer;" title="Configure languange"&gt;c&lt;/SPAN&gt;&lt;SPAN class="gmBabelMousishToolBar" style="cursor: default;" title="From English To Italian"&gt;en &amp;gt; it&lt;/SPAN&gt;&lt;IMG align="middle" src="https://communities.sas.com/" style="cursor: pointer;" title="click to translate" /&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Sep 2012 16:22:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/complex-join-with-large-tables/m-p/110994#M23011</guid>
      <dc:creator>ciro</dc:creator>
      <dc:date>2012-09-03T16:22:39Z</dc:date>
    </item>
    <item>
      <title>Re: complex join with large tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/complex-join-with-large-tables/m-p/110995#M23012</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Isn't very elegant, but does the job efficiently (efficiency claim untested &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;), assumes datasets are sorted by X Y M:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;data A_temp(drop=r_:) A_fill(keep=X Y M Z var1) ;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;merge a (in=inA) b;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;by X Y M;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;if inA then do;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; r_Z = Z;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; r_var1 = var1;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;retain r_Z r_var1;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;Z = coalescec(Z, r_Z);&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;var1 = coalesce(var1, r_var1);&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;output A_temp;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;if missing(Z) or missing(lag(Z)) and not first.Y then output A_fill;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;if last.Y then call missing(r_Z, r_var1);&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;proc sort data=A_fill; by X Y descending M; run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;data A_upd(drop=r_:);&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;set A_fill;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;by X Y;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;if missing(Z) and not first.Y then do;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Z = r_Z;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var1 = r_var1;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;else do;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; r_Z = Z;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; r_var1 = var1;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;retain r_Z r_var1;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;if last.Y then call missing(r_Z, r_var1);&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;proc sort data=A_upd; by X Y M; run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;data A_after;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;update A_temp A_upd;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;by X Y M;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt; &lt;BR /&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;proc print data=a_after; run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Sep 2012 21:38:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/complex-join-with-large-tables/m-p/110995#M23012</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2012-09-03T21:38:06Z</dc:date>
    </item>
    <item>
      <title>Re: complex join with large tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/complex-join-with-large-tables/m-p/110996#M23013</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It is not too fast.&lt;/P&gt;&lt;P&gt;Assuming there is unique combination of x y m for both datasets.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data A;
input X $ Y $ M Z $ var1 ;
cards;
A 0001 1 P 10
A 0001 2 P 11
A 0001 3 P 12
A 0001 4 P 13
A 0001 8 P 17
A 0001 9 P 18
A 0001 10 P 20
A 0002 4 P 21
A 0002 5 P 23
A 0002 6 P 25
A 0002 7 P 27
A 0002 8 P 27
A 0002 9 P 20
A 0002 10 P 15
A 0002 11 P 14
A 0002 12 P 12
B 0041 1 F 18
B 0041 2 F 18
B 0041 3 F 19
B 0041 4 F 20
B 0041 5 F 21
B 0041 6 F 17
B 0041 7 F 17
B 0041 8 F 17
B 0041 9 F 20
;
run;
data B;
input X $ Y $ M S $ var2 ;
cards;
A 0001 5 E 4
A 0001 6 E 4
A 0001 7 E 6
A 0001 10 O 2
A 0001 12 E 6
A 0002 3 E 4
B 0041 8 O 5
B 0041 9 O 6
B 0041 10 E 6
B 0041 11 E 6
;
run;
data temp(drop=_:);
 set a(in=ina) b ;
 by x y m;
 retain _z _var1;
 if ina then do;_z=z;_var1=var1; end;
&amp;nbsp;&amp;nbsp; else&amp;nbsp; do;z=_z;var1=_var1; end;
run;
data want;
 set temp;
 by x y m ;
 if last.m;
run;



&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: xia keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Sep 2012 04:25:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/complex-join-with-large-tables/m-p/110996#M23013</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-09-04T04:25:42Z</dc:date>
    </item>
    <item>
      <title>Re: complex join with large tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/complex-join-with-large-tables/m-p/110997#M23014</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;f you know the largest gap in A, (i.e. the largest number of B records that separate 2 A records), then you can do this (which assumes the largest gap is 4 B records).&amp;nbsp; It provides&amp;nbsp; a single step solution, without reversion to hash or DOW loop:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set a b;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by x y m;&lt;/P&gt;&lt;P&gt;&amp;nbsp; z=coalescec(z,lag(z),lag2(z),lag3(z),lag4(z));&lt;/P&gt;&lt;P&gt;&amp;nbsp; var1=coalesce(var1,lag(var1),lag2(var1),lag3(var1),lag4(var1));&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This assumes (1) A and B are sorted by x y m, and (2) first record for a given X/Y is from A which always has a valid value for Z and VAR1.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Sep 2012 16:30:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/complex-join-with-large-tables/m-p/110997#M23014</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2012-09-04T16:30:30Z</dc:date>
    </item>
    <item>
      <title>Re: complex join with large tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/complex-join-with-large-tables/m-p/110998#M23015</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thank you everybody. I'll try some of the suggestions. no hashing though. isn't it useful in such a situation? As a further information I need the data in sas (not sure if temporary or permanent dataset) they are subject to further processing.&amp;nbsp; &lt;/P&gt;&lt;DIV id="gmBabelFish" style="border: 1px solid black; display: none; position: absolute; background-color: #a8ecff; padding: 2px; font-size: 12px; color: black; text-align: left; z-index: 100;"&gt;&lt;DIV style="border-bottom: 1px dotted black; padding-bottom: 2px; padding-top: 2px;"&gt;&lt;SPAN class="gmBabelMousishToolBar" style="cursor: pointer;" title="Close babel mousish"&gt;x&lt;/SPAN&gt;&lt;SPAN class="gmBabelMousishToolBar" style="cursor: pointer;" title="Configure languange"&gt;c&lt;/SPAN&gt;&lt;SPAN class="gmBabelMousishToolBar" style="cursor: default;" title="From English To Italian"&gt;en &amp;gt; it&lt;/SPAN&gt;&lt;IMG align="middle" src="https://communities.sas.com/" style="cursor: pointer;" title="click to translate" /&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Sep 2012 13:38:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/complex-join-with-large-tables/m-p/110998#M23015</guid>
      <dc:creator>ciro</dc:creator>
      <dc:date>2012-09-06T13:38:17Z</dc:date>
    </item>
    <item>
      <title>Re: complex join with large tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/complex-join-with-large-tables/m-p/110999#M23016</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;OK, one more country heard from:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; merge a (in=ina) b (in=inb);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; by x y m;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if first.y then a_record_found=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if ina then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a_records_read + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a_record_found = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; retain a_record_found;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if inb and not ina;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if a_record_found then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pointer = a_records_read -1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set a point=pointer (keep=var1);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; else do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pointer = a_records_read + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set a pointer=pointer (keep=x y var1 rename=(x=proposed_match_x y=proposed_match_y var1=proposed_var1));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if x=proposed_match_x and y=proposed_match_y then var1=proposed_var1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; drop proposed_: a_record:;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This might get a little unwieldy, depending on how many variables are really represented by "var1".&amp;nbsp; And it does account for a new subject (X Y) appearing in B that doesn't appear in A (as long as that new subject is NOT the last one in the combined file ... tweaks are possible if necessary).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Sep 2012 15:27:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/complex-join-with-large-tables/m-p/110999#M23016</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2012-09-06T15:27:31Z</dc:date>
    </item>
  </channel>
</rss>

