<?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: Exact woking of Merge operation (IF A AND B)? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Exact-woking-of-Merge-operation-IF-A-AND-B/m-p/279940#M56495</link>
    <description>&lt;P&gt;jkl and iop are two temporary variables (created throught the dataset options in the merge statement and not included in the output dataset(s)) that are set to 1 if a record from the respective dataset is present, and zero otherwise.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if jkl and iop;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is a so-called "subsetting if" and therefore means that if a record (for the current "by" value) is missing from either dataset, the current iteration of the data step is terminated and no output is written.&lt;/P&gt;</description>
    <pubDate>Fri, 24 Jun 2016 10:22:52 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2016-06-24T10:22:52Z</dc:date>
    <item>
      <title>Exact woking of Merge operation (IF A AND B)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exact-woking-of-Merge-operation-IF-A-AND-B/m-p/279929#M56489</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am using the merge statement as follows(In SAS University edition):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;libname Temp '/folders/myfolders';&lt;BR /&gt;&lt;BR /&gt;data Temp.merge_calls_2;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;merge Temp.trans_2 (in=jkl) Temp.trans_3 (in=iop);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;by col1 col2;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if jkl and iop;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc print data=Temp.merge_calls_2;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;title Merge_Calls2;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In some cases this logic provides me the output similar to SQL Inner join where as, sometimes the output is different.&lt;/P&gt;&lt;P&gt;Can some one pl. explain the exact working of the above merge operation and also a appropriate SQL query to get the same output .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks In Advance.&lt;/P&gt;&lt;P&gt;CP.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2016 08:55:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exact-woking-of-Merge-operation-IF-A-AND-B/m-p/279929#M56489</guid>
      <dc:creator>chaitalip</dc:creator>
      <dc:date>2016-06-24T08:55:27Z</dc:date>
    </item>
    <item>
      <title>Re: Exact woking of Merge operation (IF A AND B)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exact-woking-of-Merge-operation-IF-A-AND-B/m-p/279932#M56490</link>
      <description>&lt;P&gt;Yes, inner join is the nearest to that, see below graphic of the various joins. &amp;nbsp;Obviously the output depends on you data - i.e. multiple entries on either side and such like. &amp;nbsp;The datastep works by assigning a variable to each dataset which indicates which dataset it comes from, think of it like a new variable. &amp;nbsp;The if statement just checks that the merged record is present in both datasets.&lt;/P&gt;
&lt;P&gt;Am not going over the full process, that is where the manual comes in:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/viewer.htm#a001318494.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/viewer.htm#a001318494.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Or training:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.ats.ucla.edu/stat/sas/modules/merge.htm" target="_blank"&gt;http://www.ats.ucla.edu/stat/sas/modules/merge.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/3736i3E5EEED09A5B6EC1/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2016 09:20:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exact-woking-of-Merge-operation-IF-A-AND-B/m-p/279932#M56490</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-06-24T09:20:48Z</dc:date>
    </item>
    <item>
      <title>Re: Exact woking of Merge operation (IF A AND B)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exact-woking-of-Merge-operation-IF-A-AND-B/m-p/279937#M56493</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;the above mentioned link is good but i am not able to get the exact working of &amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;if jkl and iop&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;From the above posted code by me.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Thanks in advance.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;CP.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2016 09:56:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exact-woking-of-Merge-operation-IF-A-AND-B/m-p/279937#M56493</guid>
      <dc:creator>chaitalip</dc:creator>
      <dc:date>2016-06-24T09:56:43Z</dc:date>
    </item>
    <item>
      <title>Re: Exact woking of Merge operation (IF A AND B)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exact-woking-of-Merge-operation-IF-A-AND-B/m-p/279940#M56495</link>
      <description>&lt;P&gt;jkl and iop are two temporary variables (created throught the dataset options in the merge statement and not included in the output dataset(s)) that are set to 1 if a record from the respective dataset is present, and zero otherwise.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if jkl and iop;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is a so-called "subsetting if" and therefore means that if a record (for the current "by" value) is missing from either dataset, the current iteration of the data step is terminated and no output is written.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2016 10:22:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exact-woking-of-Merge-operation-IF-A-AND-B/m-p/279940#M56495</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-06-24T10:22:52Z</dc:date>
    </item>
    <item>
      <title>Re: Exact woking of Merge operation (IF A AND B)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exact-woking-of-Merge-operation-IF-A-AND-B/m-p/279944#M56496</link>
      <description>&lt;P&gt;What type,of merge are you trying to do, one to one, one to many, or many to many?&lt;/P&gt;
&lt;P&gt;Typically these are what cause the differences between a data step and proc SQL and mess up how you think the IN and IF should work.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2016 11:03:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exact-woking-of-Merge-operation-IF-A-AND-B/m-p/279944#M56496</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-24T11:03:24Z</dc:date>
    </item>
    <item>
      <title>Re: Exact woking of Merge operation (IF A AND B)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exact-woking-of-Merge-operation-IF-A-AND-B/m-p/280325#M56627</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; I think its Many-to-many merging because there are duplicates in both data set.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jun 2016 05:52:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exact-woking-of-Merge-operation-IF-A-AND-B/m-p/280325#M56627</guid>
      <dc:creator>chaitalip</dc:creator>
      <dc:date>2016-06-27T05:52:23Z</dc:date>
    </item>
    <item>
      <title>Re: Exact woking of Merge operation (IF A AND B)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exact-woking-of-Merge-operation-IF-A-AND-B/m-p/280326#M56628</link>
      <description>&lt;P&gt;In a many-to-many merge, SQL will create a cartesian join, while the datastep just goes through them sequentially.&lt;/P&gt;
&lt;P&gt;eg dataset X has 3 obs for A = 1, while dataset Y has 2 obs for A = 1:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table Z as 
select X.*
from X inner join Y
on X.A = Y.A
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;willl create dataset Z with 6 observations; all individual obs from X are joined with all individual obs from Y.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Z;
merge
  X (in=in_x)
  Y (in=in_y)
;
by A;
if in_x and in_y;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will create dataset Z with 3 observations.&lt;/P&gt;
&lt;P&gt;With the data step, Z will have the following observations for A = 1:&lt;/P&gt;
&lt;P&gt;1st: data from first obs from X and first obs from Y&lt;/P&gt;
&lt;P&gt;2nd: data from second obs from X and second obs from Y&lt;/P&gt;
&lt;P&gt;3rd: data from third obs from X and second obs from Y&lt;/P&gt;
&lt;P&gt;Once the last record from a BY group is read from one of the participating datasets, its contents will stay in the PDV until no more records for the same BY group come from the other datasets.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jun 2016 06:12:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exact-woking-of-Merge-operation-IF-A-AND-B/m-p/280326#M56628</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-06-27T06:12:19Z</dc:date>
    </item>
    <item>
      <title>Re: Exact woking of Merge operation (IF A AND B)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exact-woking-of-Merge-operation-IF-A-AND-B/m-p/280327#M56629</link>
      <description>&lt;P&gt;A many to many merge in a data step does not give you the same results as using a SQL join.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Usually I prefer a SQL step for these joins as the results are more intuitive.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a SAS note regarding this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/kb/24/752.html" target="_blank"&gt;http://support.sas.com/kb/24/752.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jun 2016 06:13:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exact-woking-of-Merge-operation-IF-A-AND-B/m-p/280327#M56629</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-27T06:13:06Z</dc:date>
    </item>
    <item>
      <title>Re: Exact woking of Merge operation (IF A AND B)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exact-woking-of-Merge-operation-IF-A-AND-B/m-p/280379#M56652</link>
      <description>&lt;P&gt;Thank you for your reply,&lt;/P&gt;&lt;P&gt;Just one more query. Can you provide equivalent SQL query to get the same output.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;CP.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jun 2016 11:56:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exact-woking-of-Merge-operation-IF-A-AND-B/m-p/280379#M56652</guid>
      <dc:creator>chaitalip</dc:creator>
      <dc:date>2016-06-27T11:56:45Z</dc:date>
    </item>
    <item>
      <title>Re: Exact woking of Merge operation (IF A AND B)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exact-woking-of-Merge-operation-IF-A-AND-B/m-p/280381#M56653</link>
      <description>&lt;P&gt;From where does your obsession with SQL come from? If the data step does what you want, stay with it.&lt;/P&gt;
&lt;P&gt;(Answer to your question: none, as there isn't one. At least one that makes sense. SQL behaves differently, period)&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jun 2016 12:01:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exact-woking-of-Merge-operation-IF-A-AND-B/m-p/280381#M56653</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-06-27T12:01:29Z</dc:date>
    </item>
  </channel>
</rss>

