<?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: Match Merging By Two Variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Match-Merging-By-Two-Variables/m-p/251299#M47454</link>
    <description>&lt;P&gt;You just missed a minor option:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data  Merged_Dataset;
   merge Dataset1 
         Dataset2 (in = in2);
   by Variable1 Variable2;
   if in2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The dataset option IN sets a temporary variable as named (in2 in my example) to 1 when the dataset contributes any part of the observation. The IF then only keeps values when that variable is 1 (or True).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can extend this quite easily to do calculations based on contributions from one or both data sets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another option is Proc SQL and a Right or Left Join.&lt;/P&gt;</description>
    <pubDate>Fri, 19 Feb 2016 22:12:59 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2016-02-19T22:12:59Z</dc:date>
    <item>
      <title>Match Merging By Two Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merging-By-Two-Variables/m-p/251288#M47450</link>
      <description>&lt;P&gt;Hi SAS users,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to match merge two data set having two common variables as below (here is a small portion of the dataset for simplicity):&lt;/P&gt;&lt;P&gt;--------------------------------------------------&lt;/P&gt;&lt;P&gt;Dataset1:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;variable1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;variable2&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; a &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 15&lt;/P&gt;&lt;P&gt;--------------------------------------------------&lt;/P&gt;&lt;P&gt;Dataset2:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;variable1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;variable2&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 15&lt;/P&gt;&lt;P&gt;---------------------------------------------------&lt;/P&gt;&lt;P&gt;After merging, my output is like&amp;nbsp;this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Merged_Dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;variable1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;variable2&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; a &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; a &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;15&lt;/P&gt;&lt;P&gt;-------------------------------------------------------&lt;/P&gt;&lt;P&gt;However, I expect the final output to be like below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Desired_Dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;variable1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;variable2&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; a &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;15&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please help?, the code I used is as below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;data &amp;nbsp;&lt;SPAN&gt;Merged_Dataset&lt;/SPAN&gt;;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;merge &lt;SPAN&gt;Dataset1&lt;/SPAN&gt; &lt;SPAN&gt;Dataset2&lt;/SPAN&gt;&amp;nbsp;;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;by Variable1&amp;nbsp;Variable2;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;run;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Feb 2016 21:51:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merging-By-Two-Variables/m-p/251288#M47450</guid>
      <dc:creator>almmotamedi</dc:creator>
      <dc:date>2016-02-19T21:51:18Z</dc:date>
    </item>
    <item>
      <title>Re: Match Merging By Two Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merging-By-Two-Variables/m-p/251298#M47453</link>
      <description>&lt;P&gt;Look up the IN options for datasets.&lt;/P&gt;
&lt;P&gt;You need to specify that you want records from both datasets.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Feb 2016 22:12:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merging-By-Two-Variables/m-p/251298#M47453</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-02-19T22:12:42Z</dc:date>
    </item>
    <item>
      <title>Re: Match Merging By Two Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merging-By-Two-Variables/m-p/251299#M47454</link>
      <description>&lt;P&gt;You just missed a minor option:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data  Merged_Dataset;
   merge Dataset1 
         Dataset2 (in = in2);
   by Variable1 Variable2;
   if in2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The dataset option IN sets a temporary variable as named (in2 in my example) to 1 when the dataset contributes any part of the observation. The IF then only keeps values when that variable is 1 (or True).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can extend this quite easily to do calculations based on contributions from one or both data sets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another option is Proc SQL and a Right or Left Join.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Feb 2016 22:12:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merging-By-Two-Variables/m-p/251299#M47454</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-02-19T22:12:59Z</dc:date>
    </item>
    <item>
      <title>Re: Match Merging By Two Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merging-By-Two-Variables/m-p/251302#M47457</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw﻿&lt;/a&gt;&amp;nbsp;Code assumes all records in table 2. If your criteria is records in both tables it would be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data  Merged_Dataset;
   merge Dataset1 (in=in1)
         Dataset2 (in = in2);
   by Variable1 Variable2;
   if in1 and in2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Feb 2016 22:22:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merging-By-Two-Variables/m-p/251302#M47457</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-02-19T22:22:34Z</dc:date>
    </item>
    <item>
      <title>Re: Match Merging By Two Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-Merging-By-Two-Variables/m-p/251304#M47459</link>
      <description>Thank you</description>
      <pubDate>Fri, 19 Feb 2016 22:29:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-Merging-By-Two-Variables/m-p/251304#M47459</guid>
      <dc:creator>almmotamedi</dc:creator>
      <dc:date>2016-02-19T22:29:49Z</dc:date>
    </item>
  </channel>
</rss>

