<?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 SAS merge statement equivanet in SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-merge-statement-equivanet-in-SQL/m-p/344479#M79162</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have a question on how to use a merge statement in SQL. That I would like to "convert" the following merge statment in SQL.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;merge have1 (in=a) have2 (in=b);&lt;/P&gt;&lt;P&gt;by var1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if a=1 and b=1 then match='All';&lt;/P&gt;&lt;P&gt;else if a=1 and b=0 then match='have1';&lt;/P&gt;&lt;P&gt;else if a=0 and b=1 then match='have2';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know one can use the where the statement in SQL but that would be equivalent to the match='All' statement above, right? I want to also be able to see where there is data in one table but not the other and vise versa? Is it a join statment? But I also would like to create a new varaible like 'match' so it can flag the rows that match between two datasets and those that dont.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any recommendation would be great!&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Mon, 27 Mar 2017 01:05:24 GMT</pubDate>
    <dc:creator>sas_student1</dc:creator>
    <dc:date>2017-03-27T01:05:24Z</dc:date>
    <item>
      <title>SAS merge statement equivanet in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-merge-statement-equivanet-in-SQL/m-p/344479#M79162</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have a question on how to use a merge statement in SQL. That I would like to "convert" the following merge statment in SQL.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;merge have1 (in=a) have2 (in=b);&lt;/P&gt;&lt;P&gt;by var1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if a=1 and b=1 then match='All';&lt;/P&gt;&lt;P&gt;else if a=1 and b=0 then match='have1';&lt;/P&gt;&lt;P&gt;else if a=0 and b=1 then match='have2';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know one can use the where the statement in SQL but that would be equivalent to the match='All' statement above, right? I want to also be able to see where there is data in one table but not the other and vise versa? Is it a join statment? But I also would like to create a new varaible like 'match' so it can flag the rows that match between two datasets and those that dont.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any recommendation would be great!&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2017 01:05:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-merge-statement-equivanet-in-SQL/m-p/344479#M79162</guid>
      <dc:creator>sas_student1</dc:creator>
      <dc:date>2017-03-27T01:05:24Z</dc:date>
    </item>
    <item>
      <title>Re: SAS merge statement equivanet in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-merge-statement-equivanet-in-SQL/m-p/344480#M79163</link>
      <description>&lt;P&gt;Yes, a join is what you need, most likely a full join, I can't seem to paste links for some reason so search sql join and you should see a diagram with red circles.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use a CASE statement with your logic.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You won't have the automatic variables but you can use the BY variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming VAR1 has no missing values, the following is the CASE logic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case when missing(var1) then 'status 1'
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;when missing(b.var1) then 'status 2'
&amp;nbsp; &amp;nbsp; &amp;nbsp;when a.var1=b.var1) then 'match'
else 'CHECKME' end as match&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2017 01:11:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-merge-statement-equivanet-in-SQL/m-p/344480#M79163</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-27T01:11:22Z</dc:date>
    </item>
  </channel>
</rss>

