<?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 Merge with OR statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-OR-statement/m-p/19145#M2950</link>
    <description>Hi all,&lt;BR /&gt;
          I want to merge 2 datasets where one of the by variables could be equal to any of the 2 variables in the other dataset&lt;BR /&gt;
&lt;BR /&gt;
Eg&lt;BR /&gt;
&lt;BR /&gt;
Dataset A variables:  ID ,Amt, Serial1&lt;BR /&gt;
Dataset B variables:  ID ,Amt, SerialA, SerialB&lt;BR /&gt;
&lt;BR /&gt;
 The by variable Serial1 in datasetA could by same as SerialA or SerialB. ID is also a by variable.&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
&lt;BR /&gt;
Amit</description>
    <pubDate>Wed, 15 Apr 2009 16:00:30 GMT</pubDate>
    <dc:creator>AmitKB</dc:creator>
    <dc:date>2009-04-15T16:00:30Z</dc:date>
    <item>
      <title>Merge with OR statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-OR-statement/m-p/19145#M2950</link>
      <description>Hi all,&lt;BR /&gt;
          I want to merge 2 datasets where one of the by variables could be equal to any of the 2 variables in the other dataset&lt;BR /&gt;
&lt;BR /&gt;
Eg&lt;BR /&gt;
&lt;BR /&gt;
Dataset A variables:  ID ,Amt, Serial1&lt;BR /&gt;
Dataset B variables:  ID ,Amt, SerialA, SerialB&lt;BR /&gt;
&lt;BR /&gt;
 The by variable Serial1 in datasetA could by same as SerialA or SerialB. ID is also a by variable.&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
&lt;BR /&gt;
Amit</description>
      <pubDate>Wed, 15 Apr 2009 16:00:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-OR-statement/m-p/19145#M2950</guid>
      <dc:creator>AmitKB</dc:creator>
      <dc:date>2009-04-15T16:00:30Z</dc:date>
    </item>
    <item>
      <title>Re: Merge with OR statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-OR-statement/m-p/19146#M2951</link>
      <description>You could easily do this with a single SQL statement (where SERIAL1 = SERIALA or SERIAL1 = SERIALB).&lt;BR /&gt;
&lt;BR /&gt;
For a datastep merge solution, you should do a 3 table merge, being the third table a copy of dataset B. Assuming that dataset A is sorted by SerialA, it would look like this;&lt;BR /&gt;
&lt;BR /&gt;
data BB; /* copy B to BB */&lt;BR /&gt;
set B;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sort; /* sort BB by SerialB */&lt;BR /&gt;
by SerialB;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data RESULT; /* do the 3 table merge */&lt;BR /&gt;
merge A (in = a)&lt;BR /&gt;
B (in = b rename = (SerialA=Serial1) drop = SerialB)&lt;BR /&gt;
BB (in = bb rename = (SerialB=Serial1) drop = SerialA);&lt;BR /&gt;
by Serial1;&lt;BR /&gt;
if a and (b or bb); /* match by Serial1=SerialA or Serial1=SerialB */&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Greetings from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos at &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;</description>
      <pubDate>Wed, 15 Apr 2009 16:59:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-OR-statement/m-p/19146#M2951</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2009-04-15T16:59:24Z</dc:date>
    </item>
    <item>
      <title>Re: Merge with OR statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-OR-statement/m-p/19147#M2952</link>
      <description>Hi Daniel,&lt;BR /&gt;
               Thanks a lot for the solution. I will implement it both ways, to gain more confidence in proc sql ( trying to learning it)&lt;BR /&gt;
&lt;BR /&gt;
Thanks.&lt;BR /&gt;
&lt;BR /&gt;
Amit</description>
      <pubDate>Wed, 15 Apr 2009 17:40:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-OR-statement/m-p/19147#M2952</guid>
      <dc:creator>AmitKB</dc:creator>
      <dc:date>2009-04-15T17:40:21Z</dc:date>
    </item>
  </channel>
</rss>

