<?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 Many to one merge with overlapping variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Many-to-one-merge-with-overlapping-variables/m-p/173119#M33229</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is an exampe of what i would like to do &lt;/P&gt;&lt;P&gt;data A;&lt;/P&gt;&lt;P&gt;input @1 id @3 x;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1 0&lt;/P&gt;&lt;P&gt;1 0&lt;/P&gt;&lt;P&gt;1 0&lt;/P&gt;&lt;P&gt;2 0&lt;/P&gt;&lt;P&gt;2 0&lt;/P&gt;&lt;P&gt;3 0&lt;/P&gt;&lt;P&gt;3 0&lt;/P&gt;&lt;P&gt;3 0&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 B;&lt;/P&gt;&lt;P&gt;input @1 id&amp;nbsp; @3 x;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1 1&lt;/P&gt;&lt;P&gt;2 3&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;Dataset B has at most one observation per id whereas dataset A has (possibly multiple) obervations for all ids.&lt;/P&gt;&lt;P&gt;I would like to update colum x from A with column x from B so that A finally contains&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1 1&lt;/P&gt;&lt;P&gt;1 1&lt;/P&gt;&lt;P&gt;1 1&lt;/P&gt;&lt;P&gt;2 3&lt;/P&gt;&lt;P&gt;2 3&lt;/P&gt;&lt;P&gt;3 3&lt;/P&gt;&lt;P&gt;3 0&lt;/P&gt;&lt;P&gt;3 0&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To be more precise, i need to do this for several columns and not just one as in the example.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So far, I obtained the result using something like :&lt;/P&gt;&lt;P&gt;proc sort data=A; by id; run;&lt;/P&gt;&lt;P&gt;proc sort data=B; by id; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data A;&lt;/P&gt;&lt;P&gt;&amp;nbsp; merge A (in=a) B(in=b rename=(x=x2));&lt;BR /&gt;&amp;nbsp; by id;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if b then x=x2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if a;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; drop x2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a better way to get the same result ?&lt;/P&gt;&lt;P&gt;By better, I mean :&lt;/P&gt;&lt;P&gt;- more efficient (dataset A will contain between 30 000 and 50 000 records, B is typically much&lt;/P&gt;&lt;P&gt;smaller - a few hundreds, the update concerns a dozen of variables)&lt;/P&gt;&lt;P&gt;- more elegant. In particular, I am not very pleased with the need to rename the variables&lt;/P&gt;&lt;P&gt;although they have the same name in both datasets.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 13 Feb 2014 12:41:38 GMT</pubDate>
    <dc:creator>gamotte</dc:creator>
    <dc:date>2014-02-13T12:41:38Z</dc:date>
    <item>
      <title>Many to one merge with overlapping variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Many-to-one-merge-with-overlapping-variables/m-p/173119#M33229</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is an exampe of what i would like to do &lt;/P&gt;&lt;P&gt;data A;&lt;/P&gt;&lt;P&gt;input @1 id @3 x;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1 0&lt;/P&gt;&lt;P&gt;1 0&lt;/P&gt;&lt;P&gt;1 0&lt;/P&gt;&lt;P&gt;2 0&lt;/P&gt;&lt;P&gt;2 0&lt;/P&gt;&lt;P&gt;3 0&lt;/P&gt;&lt;P&gt;3 0&lt;/P&gt;&lt;P&gt;3 0&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 B;&lt;/P&gt;&lt;P&gt;input @1 id&amp;nbsp; @3 x;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1 1&lt;/P&gt;&lt;P&gt;2 3&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;Dataset B has at most one observation per id whereas dataset A has (possibly multiple) obervations for all ids.&lt;/P&gt;&lt;P&gt;I would like to update colum x from A with column x from B so that A finally contains&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1 1&lt;/P&gt;&lt;P&gt;1 1&lt;/P&gt;&lt;P&gt;1 1&lt;/P&gt;&lt;P&gt;2 3&lt;/P&gt;&lt;P&gt;2 3&lt;/P&gt;&lt;P&gt;3 3&lt;/P&gt;&lt;P&gt;3 0&lt;/P&gt;&lt;P&gt;3 0&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To be more precise, i need to do this for several columns and not just one as in the example.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So far, I obtained the result using something like :&lt;/P&gt;&lt;P&gt;proc sort data=A; by id; run;&lt;/P&gt;&lt;P&gt;proc sort data=B; by id; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data A;&lt;/P&gt;&lt;P&gt;&amp;nbsp; merge A (in=a) B(in=b rename=(x=x2));&lt;BR /&gt;&amp;nbsp; by id;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if b then x=x2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if a;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; drop x2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a better way to get the same result ?&lt;/P&gt;&lt;P&gt;By better, I mean :&lt;/P&gt;&lt;P&gt;- more efficient (dataset A will contain between 30 000 and 50 000 records, B is typically much&lt;/P&gt;&lt;P&gt;smaller - a few hundreds, the update concerns a dozen of variables)&lt;/P&gt;&lt;P&gt;- more elegant. In particular, I am not very pleased with the need to rename the variables&lt;/P&gt;&lt;P&gt;although they have the same name in both datasets.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Feb 2014 12:41:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Many-to-one-merge-with-overlapping-variables/m-p/173119#M33229</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2014-02-13T12:41:38Z</dc:date>
    </item>
    <item>
      <title>Re: Many to one merge with overlapping variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Many-to-one-merge-with-overlapping-variables/m-p/173120#M33230</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try making a format out of your smaller data using proc format and cntlin= option.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then apply that format to your key variables in the big dataset to create the values for the variable you are after.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Feb 2014 14:23:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Many-to-one-merge-with-overlapping-variables/m-p/173120#M33230</guid>
      <dc:creator>peterz</dc:creator>
      <dc:date>2014-02-13T14:23:55Z</dc:date>
    </item>
    <item>
      <title>Re: Many to one merge with overlapping variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Many-to-one-merge-with-overlapping-variables/m-p/173121#M33231</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could use PROC SQL.&lt;/P&gt;&lt;P&gt;PROC SQL ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table A_updated as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select A.id, COALESCE(B.x, A.x) as x&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from A&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; left outer join B on A.id = B.id ;&lt;/P&gt;&lt;P&gt;quit ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It has the benefit of not needing to pre-sort the two datasets, so you save some CPU and I/O there.&lt;/P&gt;&lt;P&gt;I have been wanting to run some independent tests to see the CPU and I/O costs for the two different methods, but haven't had the time.&lt;/P&gt;&lt;P&gt;You might report back on your tests.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note:&amp;nbsp; if you have multiple variables that need to be updated at the same time, you can do them all at once, using the COALESCE on each variable.&lt;/P&gt;&lt;P&gt;so if table A has variables id, x, y and z, and table B has the same variables:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC SQL ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table A_updated as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select A.id&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; , COALESCE(B.x, A.x) as x&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; , COALESCE(B.y, A.y) as y&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; , COALESCE(B.z, A.z) as z&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from A&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; left outer join B on A.id = B.id ;&lt;/P&gt;&lt;P&gt;quit ;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Feb 2014 14:27:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Many-to-one-merge-with-overlapping-variables/m-p/173121#M33231</guid>
      <dc:creator>cwilson</dc:creator>
      <dc:date>2014-02-13T14:27:23Z</dc:date>
    </item>
    <item>
      <title>Re: Many to one merge with overlapping variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Many-to-one-merge-with-overlapping-variables/m-p/173122#M33232</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks peterz and cwilson.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would never have thought to use a format for this purpose, really clever.&lt;/P&gt;&lt;P&gt;I think I will rather use the COALESCE option though as I'm trying to do&lt;/P&gt;&lt;P&gt;something generic (i.e. it is supposed to be part of a macro) and it seems&lt;/P&gt;&lt;P&gt;to me simpler that way.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Feb 2014 16:01:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Many-to-one-merge-with-overlapping-variables/m-p/173122#M33232</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2014-02-13T16:01:18Z</dc:date>
    </item>
    <item>
      <title>Re: Many to one merge with overlapping variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Many-to-one-merge-with-overlapping-variables/m-p/173123#M33233</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;* Here is my table A ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data A;&lt;BR /&gt;input @1 QUE1 $ @6 QUE2 $ @11 QUE3 $ @16 QUE4 $ @21 UNIQUE$;&lt;BR /&gt;cards;&lt;BR /&gt;0001 0011 0003 0011 ABCDERG1&lt;BR /&gt;0002 6934 0006 6934 ABCDERG2&lt;BR /&gt;0003 0007 6934 0010 ABCDERG3&lt;BR /&gt;0004 6935 6934 0014 ABCDERG4&lt;BR /&gt;0005 6934 0014 6934 ABCDERG4&lt;BR /&gt;0006 0002 0015 6935 ABCDERG5&lt;BR /&gt;0007 0015 6934 0015 ABCDERG6&lt;BR /&gt;0008 0017 6934 0017 ABCDERG7&lt;BR /&gt;0009 0018 0018 0018 ABCDERG8&lt;BR /&gt;6934 6934 0017 6935 ABCDERG9&lt;BR /&gt;6935 0007 6935 0017 ABCDERG0&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;* Here is my table B ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data B;&lt;BR /&gt;input @1 QUE_ALL $&amp;nbsp;&amp;nbsp; AMT 5.2;&lt;BR /&gt;cards;&lt;BR /&gt;0001 7.74&lt;BR /&gt;0002 2.90&lt;BR /&gt;0003 8.74&lt;BR /&gt;0004 6.74&lt;BR /&gt;0005 1.90&lt;BR /&gt;0006 13.74&lt;BR /&gt;0007 0.00&lt;BR /&gt;0008 6.00&lt;BR /&gt;0009 9.90&lt;BR /&gt;0010 9.74&lt;BR /&gt;0011 0.90&lt;BR /&gt;0012 5.90&lt;BR /&gt;0013 9.90&lt;BR /&gt;0014 10.24&lt;BR /&gt;0015 14.24&lt;BR /&gt;0016 17.24&lt;BR /&gt;0017 10.74&lt;BR /&gt;0018 14.74&lt;BR /&gt;0019 12.74&lt;BR /&gt;0020 11.74&lt;BR /&gt;6932 4.24&lt;BR /&gt;6933 4.49&lt;BR /&gt;6934 4.74&lt;BR /&gt;6935 4.99&lt;BR /&gt;6936 5.24&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;* Below is the output table I am looking for &lt;BR /&gt;we need to merge QUE1, QUE2 , QUE3, QUE4 from table A to QUE_ALL from table B&lt;BR /&gt;and create the new variable AMT1, AMT2, AMT3, AMT4 accordingly;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;QUE1 AMT1&amp;nbsp; QUE2&amp;nbsp; AMT2&amp;nbsp; QUE3&amp;nbsp; AMT3&amp;nbsp; UNIQUE&lt;/STRONG&gt; &lt;BR /&gt;0001&amp;nbsp;&amp;nbsp; 7.74&amp;nbsp;&amp;nbsp;&amp;nbsp; 0011&amp;nbsp;&amp;nbsp; 0.90&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0003&amp;nbsp;&amp;nbsp; 8.74&amp;nbsp;&amp;nbsp;&amp;nbsp; ABCDERG1&lt;BR /&gt;0002&amp;nbsp;&amp;nbsp; 2.90&amp;nbsp;&amp;nbsp;&amp;nbsp; 6934&amp;nbsp;&amp;nbsp; 4.74&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0006&amp;nbsp;&amp;nbsp; 13.74&amp;nbsp; ABCDERG2&lt;BR /&gt;0003&amp;nbsp;&amp;nbsp; 8.74&amp;nbsp;&amp;nbsp;&amp;nbsp; 0007&amp;nbsp;&amp;nbsp; 0.00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6934&amp;nbsp;&amp;nbsp; 4.74&amp;nbsp;&amp;nbsp;&amp;nbsp; ABCDERG3&lt;BR /&gt;0004&amp;nbsp;&amp;nbsp; 6.74&amp;nbsp;&amp;nbsp;&amp;nbsp; 6935&amp;nbsp;&amp;nbsp; 4.99&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6934&amp;nbsp;&amp;nbsp; 4.74&amp;nbsp;&amp;nbsp;&amp;nbsp; ABCDERG4&lt;BR /&gt;0005&amp;nbsp;&amp;nbsp; 1.90&amp;nbsp;&amp;nbsp;&amp;nbsp; 6934&amp;nbsp;&amp;nbsp; 4.74&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0014&amp;nbsp;&amp;nbsp; 10.24&amp;nbsp; ABCDERG4&lt;BR /&gt;0006&amp;nbsp;&amp;nbsp; 13.74&amp;nbsp; 0002&amp;nbsp;&amp;nbsp; 2.90&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0015&amp;nbsp;&amp;nbsp; 14.24&amp;nbsp; ABCDERG5&lt;BR /&gt;0007&amp;nbsp;&amp;nbsp; 0.00&amp;nbsp;&amp;nbsp;&amp;nbsp; 0015&amp;nbsp;&amp;nbsp; 14.24&amp;nbsp;&amp;nbsp; 6934&amp;nbsp;&amp;nbsp; 4.74&amp;nbsp;&amp;nbsp;&amp;nbsp; ABCDERG6&lt;BR /&gt;0008&amp;nbsp;&amp;nbsp; 6.00&amp;nbsp;&amp;nbsp;&amp;nbsp; 0017&amp;nbsp;&amp;nbsp; 10.74&amp;nbsp;&amp;nbsp; 6934&amp;nbsp;&amp;nbsp; 4.74&amp;nbsp;&amp;nbsp;&amp;nbsp; ABCDERG7&lt;BR /&gt;0009&amp;nbsp;&amp;nbsp; 9.90&amp;nbsp;&amp;nbsp;&amp;nbsp; 0018&amp;nbsp;&amp;nbsp; 14.74&amp;nbsp;&amp;nbsp; 0018&amp;nbsp;&amp;nbsp; 14.74&amp;nbsp; ABCDERG8&lt;BR /&gt;6934&amp;nbsp;&amp;nbsp; 4.74&amp;nbsp;&amp;nbsp;&amp;nbsp; 6934&amp;nbsp;&amp;nbsp; 4.74&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0017&amp;nbsp;&amp;nbsp; 10.74&amp;nbsp; ABCDERG9&lt;BR /&gt;6935&amp;nbsp;&amp;nbsp; 5.24&amp;nbsp;&amp;nbsp;&amp;nbsp; 0007&amp;nbsp;&amp;nbsp; 0.00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6935&amp;nbsp;&amp;nbsp; 4.99&amp;nbsp;&amp;nbsp;&amp;nbsp; ABCDERG0&lt;/P&gt;&lt;P&gt;;&lt;BR /&gt;* after spending whole day on this - I thought to post here.;&lt;/P&gt;&lt;P&gt;*Thank you for your help;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Apr 2015 21:55:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Many-to-one-merge-with-overlapping-variables/m-p/173123#M33233</guid>
      <dc:creator>Ranny</dc:creator>
      <dc:date>2015-04-01T21:55:25Z</dc:date>
    </item>
    <item>
      <title>Re: Many to one merge with overlapping variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Many-to-one-merge-with-overlapping-variables/m-p/173124#M33234</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is a good example of the usefulness of PROC SQL ;&lt;/P&gt;&lt;P&gt;You can merge to the same dataset multiple times, each time, merging by a different variable.&lt;/P&gt;&lt;P&gt;Notice that I added an alias to each variation on the B table to distinguish the AMT that I want, and I used a LEFT OUTER JOIN to keep the data from A in case it does not match a value in B.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql ;&lt;BR /&gt; create table AB as&lt;BR /&gt; select A.QUE1, B1.AMT as AMT1, &lt;BR /&gt; A.QUE2, B2.AMT as AMT2,&lt;BR /&gt; A.QUE3, B3.AMT as AMT3,&lt;BR /&gt; A.QUE4, B4.AMT as AMT4,&lt;BR /&gt; A.UNIQUE &lt;BR /&gt; from A&lt;BR /&gt; left outer join B as B1 on A.QUE1 = B1.QUE_ALL&lt;BR /&gt; left outer join B as B2 on A.QUE2 = B2.QUE_ALL&lt;BR /&gt; left outer join B as B3 on A.QUE3 = B3.QUE_ALL&lt;BR /&gt; left outer join B as B4 on A.QUE4 = B4.QUE_ALL&lt;/P&gt;&lt;P&gt;order by A.UNIQUE&lt;BR /&gt; ;&lt;BR /&gt;quit ;&lt;/P&gt;&lt;P&gt;proc print data = AB ;&lt;BR /&gt;run ;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Apr 2015 13:39:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Many-to-one-merge-with-overlapping-variables/m-p/173124#M33234</guid>
      <dc:creator>cwilson</dc:creator>
      <dc:date>2015-04-02T13:39:17Z</dc:date>
    </item>
    <item>
      <title>Re: Many to one merge with overlapping variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Many-to-one-merge-with-overlapping-variables/m-p/173125#M33235</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you Cwilson &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; thats what I was looking for. Perfect ...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Apr 2015 17:11:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Many-to-one-merge-with-overlapping-variables/m-p/173125#M33235</guid>
      <dc:creator>Ranny</dc:creator>
      <dc:date>2015-04-02T17:11:15Z</dc:date>
    </item>
  </channel>
</rss>

