<?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: Check source of data merging in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Check-source-of-data-merging/m-p/526223#M143273</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
 data ds1;
 input var var1 $;
 datalines;
 1   x
 2   y
 ;
 
  data ds2;
 input var var2 $;
 datalines;
 2   J
 3   N
 ;
 
 
 data dsout;

    merge   ds1 (in=a)

            ds2 (in=b);

    by var;
length dataset $10.;
 if a then dataset="ds1";
 if b then dataset ="ds2";
 if a and b then dataset="ds1+ds2";
 
run;


proc sql;
create table dsout_sql1 as 
select coalesce(a.var, b.var) as var,
        var1,
        var2,
       case when a.var =b.var then "ds1+ds2"
        when a.var = . then "ds2"
        when b.var = . then "ds1" end as dataset
 from ds1 a
 full join
 ds2 b
 on a.var = b.var;
        




&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 10 Jan 2019 22:18:06 GMT</pubDate>
    <dc:creator>kiranv_</dc:creator>
    <dc:date>2019-01-10T22:18:06Z</dc:date>
    <item>
      <title>Check source of data merging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-source-of-data-merging/m-p/526215#M143269</link>
      <description>&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Hi everyone,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;I'm trying to merge two datasets, ds1 and ds2, and create columns to indicate the source of each row in the output dataset, dsout.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;For example,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;data dsout;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; merge&amp;nbsp; &amp;nbsp;ds1 (in=a)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ds2 (in=b);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; by var;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; from_ds1 = a;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; from_ds2 = b;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;I'm wondering if there's a&amp;nbsp;simple&amp;nbsp;way&amp;nbsp;to&amp;nbsp;do that&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="arial, helvetica, sans-serif"&gt;by proc sql&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Jan 2019 21:47:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-source-of-data-merging/m-p/526215#M143269</guid>
      <dc:creator>skcussas</dc:creator>
      <dc:date>2019-01-10T21:47:29Z</dc:date>
    </item>
    <item>
      <title>Re: Check source of data merging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-source-of-data-merging/m-p/526218#M143271</link>
      <description>&lt;P&gt;Good question. Proc sql joins work by joining based on values i.e &lt;STRONG&gt;m*n&lt;/STRONG&gt; product for each by group however merge does by position of by groups record by record. Therefore in= options kinda thing wouldn't be relevant from a stand point of PDV vs product cartesian(for each by group)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course saying that, you could create a flag to keep track I suppose&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Jan 2019 21:58:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-source-of-data-merging/m-p/526218#M143271</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-01-10T21:58:47Z</dc:date>
    </item>
    <item>
      <title>Re: Check source of data merging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-source-of-data-merging/m-p/526223#M143273</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
 data ds1;
 input var var1 $;
 datalines;
 1   x
 2   y
 ;
 
  data ds2;
 input var var2 $;
 datalines;
 2   J
 3   N
 ;
 
 
 data dsout;

    merge   ds1 (in=a)

            ds2 (in=b);

    by var;
length dataset $10.;
 if a then dataset="ds1";
 if b then dataset ="ds2";
 if a and b then dataset="ds1+ds2";
 
run;


proc sql;
create table dsout_sql1 as 
select coalesce(a.var, b.var) as var,
        var1,
        var2,
       case when a.var =b.var then "ds1+ds2"
        when a.var = . then "ds2"
        when b.var = . then "ds1" end as dataset
 from ds1 a
 full join
 ds2 b
 on a.var = b.var;
        




&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Jan 2019 22:18:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-source-of-data-merging/m-p/526223#M143273</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2019-01-10T22:18:06Z</dc:date>
    </item>
    <item>
      <title>Re: Check source of data merging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-source-of-data-merging/m-p/526281#M143299</link>
      <description>&lt;P&gt;You can approximate the same operation with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ds1;
 input var var1 $;
 datalines;
 1   x
 2   y
 ;
 
 data ds2;
 input var var2 $;
 datalines;
 2   J
 3   N
 ;

proc sql;
select 
    *, 
    not missing(ds1.var) as inDs1,
    not missing(ds2.var) as inDs2
from
ds1 natural full join ds2
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;sort of...&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jan 2019 04:45:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-source-of-data-merging/m-p/526281#M143299</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-01-11T04:45:05Z</dc:date>
    </item>
  </channel>
</rss>

