<?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: Data Merge vs. Proc Sql Merge in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Data-Merge-vs-Proc-Sql-Merge/m-p/930471#M366086</link>
    <description>&lt;PRE&gt;proc sql;
create table merge_data as
select t1.*, t2.*
from (select *, 1 as data1 from data_1 ) t1
left join (select *, 1 as data2 from data_2) t2 on t1.id=t2.id;&lt;/PRE&gt;
&lt;P&gt;However with a LEFT join there the variable Data1 will always be 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that the outer Select, where you have select t1.*, t2.* doesn't need to actually keep data1 and data2 but the variables can be used in a Case clause to set the "merge" status you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/466351"&gt;@trevand&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;this is the code I am using for the proc sql merge. How would you add the merge variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
create table merge_data as
select t1.*, t2.*
from data_1 t1
left join data_2 t2 on t1.id=t2.id;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 31 May 2024 19:09:46 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2024-05-31T19:09:46Z</dc:date>
    <item>
      <title>Data Merge vs. Proc Sql Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Merge-vs-Proc-Sql-Merge/m-p/930453#M366080</link>
      <description>&lt;P&gt;I would like to have a variable that tells me which observations have merged and which have not. I would like to create this in the merge step. I can do it when I use merge within the data step. I can't however figure out how I would do it with a proc sql merge. Could anyone help me please? Here is the code that creates this variable in the data step.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data data_merged;
merge data_1 (in=a) data_2 (in=b);
by merge_id;
data1=a; 
data2=b;
     if data1=1 &amp;amp; data2=1 then merge=3;
else if data1=0 &amp;amp; data2=1 then merge=2;
else if data1=1 &amp;amp; data2=0 then merge=1;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 31 May 2024 16:46:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Merge-vs-Proc-Sql-Merge/m-p/930453#M366080</guid>
      <dc:creator>trevand</dc:creator>
      <dc:date>2024-05-31T16:46:19Z</dc:date>
    </item>
    <item>
      <title>Re: Data Merge vs. Proc Sql Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Merge-vs-Proc-Sql-Merge/m-p/930456#M366083</link>
      <description>&lt;P&gt;You should share your SQL JOIN (not merge, not the same thing) code that you want to apply this to.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;you can add variable to any data set at join time by using something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;From (select *, 1 as in_a from somedataset) as a&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2024 17:20:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Merge-vs-Proc-Sql-Merge/m-p/930456#M366083</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-05-31T17:20:02Z</dc:date>
    </item>
    <item>
      <title>Re: Data Merge vs. Proc Sql Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Merge-vs-Proc-Sql-Merge/m-p/930463#M366085</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;this is the code I am using for the proc sql merge. How would you add the merge variable?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sql;
create table merge_data as
select t1.*, t2.*
from data_1 t1
left join data_2 t2 on t1.id=t2.id;&lt;/PRE&gt;</description>
      <pubDate>Fri, 31 May 2024 18:42:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Merge-vs-Proc-Sql-Merge/m-p/930463#M366085</guid>
      <dc:creator>trevand</dc:creator>
      <dc:date>2024-05-31T18:42:59Z</dc:date>
    </item>
    <item>
      <title>Re: Data Merge vs. Proc Sql Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Merge-vs-Proc-Sql-Merge/m-p/930471#M366086</link>
      <description>&lt;PRE&gt;proc sql;
create table merge_data as
select t1.*, t2.*
from (select *, 1 as data1 from data_1 ) t1
left join (select *, 1 as data2 from data_2) t2 on t1.id=t2.id;&lt;/PRE&gt;
&lt;P&gt;However with a LEFT join there the variable Data1 will always be 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that the outer Select, where you have select t1.*, t2.* doesn't need to actually keep data1 and data2 but the variables can be used in a Case clause to set the "merge" status you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/466351"&gt;@trevand&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;this is the code I am using for the proc sql merge. How would you add the merge variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
create table merge_data as
select t1.*, t2.*
from data_1 t1
left join data_2 t2 on t1.id=t2.id;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2024 19:09:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Merge-vs-Proc-Sql-Merge/m-p/930471#M366086</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-05-31T19:09:46Z</dc:date>
    </item>
    <item>
      <title>Re: Data Merge vs. Proc Sql Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Merge-vs-Proc-Sql-Merge/m-p/930485#M366091</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;how would you add the final merge variable to the proc sql code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;     if data1=1 &amp;amp; data2=1 then merge=3;
else if data1=0 &amp;amp; data2=1 then merge=2;
else if data1=1 &amp;amp; data2=0 then merge=1;&lt;/PRE&gt;</description>
      <pubDate>Fri, 31 May 2024 20:52:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Merge-vs-Proc-Sql-Merge/m-p/930485#M366091</guid>
      <dc:creator>trevand</dc:creator>
      <dc:date>2024-05-31T20:52:37Z</dc:date>
    </item>
    <item>
      <title>Re: Data Merge vs. Proc Sql Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Merge-vs-Proc-Sql-Merge/m-p/930486#M366092</link>
      <description>&lt;P&gt;Try&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table joined as
  select
    /* do NOT use asterisks, it causes a WARNING */
    /* use an exhaustive list of variables with suitable aliases instead */
    , case
      when not missing(t1.i) and not missing(t2.id) then 3
      when missing(t1.id) and not missing(t2.id) then 2
      when not missing(t1.id) and missing(t2.id) then 1&lt;BR /&gt;      else 0
    end as indicator
  from data_1 t1 full join data_2 t2
  on t1.id = t2.id
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I specifically make no reference to MERGE, as this is a SQL join, which is different from a DATA step MERGE.&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2024 21:50:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Merge-vs-Proc-Sql-Merge/m-p/930486#M366092</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-05-31T21:50:28Z</dc:date>
    </item>
    <item>
      <title>Re: Data Merge vs. Proc Sql Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Merge-vs-Proc-Sql-Merge/m-p/930488#M366094</link>
      <description>&lt;P&gt;With a Left or Right join one of those conditions NEVER appears. With a left join you can never have an observations from the "right" data set without a matching "left". Same with a right joint only the order of which can't appear reverses.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;LEFT join (on some conditios) explicitly says : Return all the observations from the "left" set and the matches that occur in the right set when present.&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2024 22:19:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Merge-vs-Proc-Sql-Merge/m-p/930488#M366094</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-05-31T22:19:08Z</dc:date>
    </item>
  </channel>
</rss>

