<?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 (IN=A) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-IN-A/m-p/845872#M334409</link>
    <description>&lt;PRE&gt;data seta;
input apple banana;
datalines;
1 1
2 2
3 3
run;

proc sort data=seta;
by apple;
run;

data setb;
input apple orange lemon pear;
datalines;
11 11 11 11
22 22 22 22
1  2 3 4 
run;

proc sort data=setb;
by apple;
run;

data outina;
merge seta (in=a) setb;
by apple;
run;

data outnoth;
merge seta setb;
by apple;
run;

proc print data=seta;
run;

proc print data=setb;
run;

proc print data=outina;
run;

proc print data=outnoth;
run;&lt;/PRE&gt;
&lt;P&gt;I am getting exact same result for with or without (in=a), why?&lt;/P&gt;
&lt;P&gt;I was believing (in=a) is like a left join... where only observations&amp;nbsp; with apple =1,2,3 would be included...&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 23 Nov 2022 11:58:36 GMT</pubDate>
    <dc:creator>HeatherNewton</dc:creator>
    <dc:date>2022-11-23T11:58:36Z</dc:date>
    <item>
      <title>Merge with (IN=A)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-IN-A/m-p/845872#M334409</link>
      <description>&lt;PRE&gt;data seta;
input apple banana;
datalines;
1 1
2 2
3 3
run;

proc sort data=seta;
by apple;
run;

data setb;
input apple orange lemon pear;
datalines;
11 11 11 11
22 22 22 22
1  2 3 4 
run;

proc sort data=setb;
by apple;
run;

data outina;
merge seta (in=a) setb;
by apple;
run;

data outnoth;
merge seta setb;
by apple;
run;

proc print data=seta;
run;

proc print data=setb;
run;

proc print data=outina;
run;

proc print data=outnoth;
run;&lt;/PRE&gt;
&lt;P&gt;I am getting exact same result for with or without (in=a), why?&lt;/P&gt;
&lt;P&gt;I was believing (in=a) is like a left join... where only observations&amp;nbsp; with apple =1,2,3 would be included...&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2022 11:58:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-IN-A/m-p/845872#M334409</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2022-11-23T11:58:36Z</dc:date>
    </item>
    <item>
      <title>Re: merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-IN-A/m-p/845878#M334412</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/416388"&gt;@HeatherNewton&lt;/a&gt;&amp;nbsp;Good question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The &lt;A href="https://documentation.sas.com/doc/en/vdmmlcdc/8.11/ledsoptsref/n1p1o2dsuc465nn198ovwdrj9mvy.htm" target="_self"&gt;IN= Data Set Option&lt;/A&gt;&amp;nbsp;&lt;EM&gt;"Creates a Boolean variable that indicates whether the data set contributed data to the current observation."&lt;/EM&gt; (Straight from the documentation). So in your example, the in=a data set option creates a 0/1 variable (automatically dropped). You can assign the value to another variable to see it in your output like below.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data outina;
merge seta (in=a) setb;
by apple;&lt;BR /&gt;ina = a;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Result:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;apple banana orange lemon pear ina
1     1      2      3     4    1
2     2      .      .     .    1
3     3      .      .     .    1
11    .      11     11    11   0
22    .      22     22    22   0&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Therefore, to replicate an SQL Left Join, you should use a Subsetting If Statement like below to output only the observations where the seta data set contributes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data outina;
merge seta (in=a) setb;
by apple;
if a;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Result:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;apple banana orange lemon pear 
1     1      2      3     4    
2     2      .      .     .    
3     3      .      .     .    &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2022 10:03:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-IN-A/m-p/845878#M334412</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-11-23T10:03:44Z</dc:date>
    </item>
    <item>
      <title>Re: Merge with (IN=A)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-IN-A/m-p/846267#M334569</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/416388"&gt;@HeatherNewton&lt;/a&gt;&amp;nbsp;, did this answer your question?&lt;/P&gt;</description>
      <pubDate>Fri, 25 Nov 2022 08:57:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-IN-A/m-p/846267#M334569</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-11-25T08:57:42Z</dc:date>
    </item>
    <item>
      <title>Re: Merge with (IN=A)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-IN-A/m-p/846268#M334570</link>
      <description>&lt;P&gt;yes thx&lt;/P&gt;</description>
      <pubDate>Fri, 25 Nov 2022 09:02:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-IN-A/m-p/846268#M334570</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2022-11-25T09:02:50Z</dc:date>
    </item>
    <item>
      <title>Re: Merge with (IN=A)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-with-IN-A/m-p/846276#M334572</link>
      <description>&lt;P&gt;Good. Please remember to close the thread &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Nov 2022 09:17:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-with-IN-A/m-p/846276#M334572</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-11-25T09:17:17Z</dc:date>
    </item>
  </channel>
</rss>

