<?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: one to many merge data issues in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/one-to-many-merge-data-issues/m-p/415989#M280172</link>
    <description>&lt;P&gt;Your merge will only create one result observation, which is identical both ways (only the sequence of variables in a row changes):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data d1;
input c1 c2 $ c3 $;
cards;
1 A B
;
run;

data d2;
input c1 c2 $ c4 $;
cards;
1 A E
1 C F
;
run;

data d3;
merge
  d1 (in=a)
  d2 (in=b)
;
by c1 c2;
if a and b;
run;

proc print data=d3 noobs;
run;

data d4;
merge
  d2 (in=b)
  d1 (in=a)
;
by c1 c2;
if a and b;
run;

proc print data=d4 noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;c1    c2    c3    c4

 1    A     B     E 
                    

c1    c2    c4    c3

 1    A     E     B 
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 24 Nov 2017 11:37:40 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-11-24T11:37:40Z</dc:date>
    <item>
      <title>one to many merge data issues</title>
      <link>https://communities.sas.com/t5/SAS-Programming/one-to-many-merge-data-issues/m-p/415938#M280170</link>
      <description>&lt;P&gt;Good morning Guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a issue with One to many Merge statement. Should we follow a specific sequence to expect the correct output.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lets say the two datasets are as below and already in sorted by C1 variable and C1 is the only common variable between D1 &amp;amp; D2.&lt;/P&gt;&lt;P&gt;(NOTE : Changed the data in&amp;nbsp;datasets for better understanding)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;D1&lt;SPAN&gt;(C1, C2, C3&amp;nbsp; are D1 data variables)&lt;/SPAN&gt;&lt;BR /&gt;C1 C2 C3&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; A&amp;nbsp; &amp;nbsp;B&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;D2&lt;SPAN&gt;(C1, C4, C5&amp;nbsp; are D2 data variables)&lt;/SPAN&gt;&lt;BR /&gt;C1 C4 C5&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; C&amp;nbsp; &amp;nbsp;D&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; E&amp;nbsp; &amp;nbsp;F&lt;/P&gt;&lt;P&gt;when i do&lt;BR /&gt;Merge D1(IN=A) D2(IN=B);&lt;/P&gt;&lt;P&gt;BY C1;&lt;BR /&gt;IF A AND B;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;OUTPUT IS LIKE :&lt;BR /&gt;C1 C2 C3 C4 C5&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; A&amp;nbsp; &amp;nbsp;B&amp;nbsp; &amp;nbsp;C&amp;nbsp; &amp;nbsp; D&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; A&amp;nbsp; &amp;nbsp;B&amp;nbsp; &amp;nbsp;E&amp;nbsp; &amp;nbsp; F&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But when am swapping datasets like&lt;BR /&gt;Merge D2(IN=A) D1(IN=B);&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;BY C1;&lt;/SPAN&gt;&lt;BR /&gt;IF A AND B;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;OUTPUT IS LIKE :&lt;BR /&gt;C1 C2 C3 C4 C5&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ------&amp;gt; C3 AND C5 variables values on first observation or missing(printed as blanks)&amp;nbsp;&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; A&amp;nbsp; &amp;nbsp;B&amp;nbsp; &amp;nbsp; E&amp;nbsp; &amp;nbsp;F&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please note that the data am using is different what i've given above.&lt;/P&gt;</description>
      <pubDate>Sat, 25 Nov 2017 06:49:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/one-to-many-merge-data-issues/m-p/415938#M280170</guid>
      <dc:creator>hsigicherla</dc:creator>
      <dc:date>2017-11-25T06:49:52Z</dc:date>
    </item>
    <item>
      <title>Re: one to many merge data issues</title>
      <link>https://communities.sas.com/t5/SAS-Programming/one-to-many-merge-data-issues/m-p/415958#M280171</link>
      <description>&lt;P&gt;When there is a same variable in both datasets, out of the by group, the data in the second dataset&lt;/P&gt;
&lt;P&gt;overides the data in fiorst one. Thus is the reason you got different results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you use update instead merge, the first dataset is the main one and the second is treated as trunsuctions.&lt;/P&gt;
&lt;P&gt;In case of missing value variable in the transaction, it will not replace the data in the main file.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Nov 2017 09:18:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/one-to-many-merge-data-issues/m-p/415958#M280171</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-11-24T09:18:20Z</dc:date>
    </item>
    <item>
      <title>Re: one to many merge data issues</title>
      <link>https://communities.sas.com/t5/SAS-Programming/one-to-many-merge-data-issues/m-p/415989#M280172</link>
      <description>&lt;P&gt;Your merge will only create one result observation, which is identical both ways (only the sequence of variables in a row changes):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data d1;
input c1 c2 $ c3 $;
cards;
1 A B
;
run;

data d2;
input c1 c2 $ c4 $;
cards;
1 A E
1 C F
;
run;

data d3;
merge
  d1 (in=a)
  d2 (in=b)
;
by c1 c2;
if a and b;
run;

proc print data=d3 noobs;
run;

data d4;
merge
  d2 (in=b)
  d1 (in=a)
;
by c1 c2;
if a and b;
run;

proc print data=d4 noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;c1    c2    c3    c4

 1    A     B     E 
                    

c1    c2    c4    c3

 1    A     E     B 
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Nov 2017 11:37:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/one-to-many-merge-data-issues/m-p/415989#M280172</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-11-24T11:37:40Z</dc:date>
    </item>
    <item>
      <title>Re: one to many merge data issues</title>
      <link>https://communities.sas.com/t5/SAS-Programming/one-to-many-merge-data-issues/m-p/416122#M280173</link>
      <description>&lt;P&gt;Hi Shmuel,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your explanation, am sorry for the confusion. But I didn't have common variables apart from group by variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks Again,&lt;/P&gt;</description>
      <pubDate>Sat, 25 Nov 2017 06:54:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/one-to-many-merge-data-issues/m-p/416122#M280173</guid>
      <dc:creator>hsigicherla</dc:creator>
      <dc:date>2017-11-25T06:54:44Z</dc:date>
    </item>
    <item>
      <title>Re: one to many merge data issues</title>
      <link>https://communities.sas.com/t5/SAS-Programming/one-to-many-merge-data-issues/m-p/416124#M280174</link>
      <description>&lt;P&gt;Hi KurtBremser,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;sorry, I was not clear in the post. and yes you are correct. I've updated the post and yes in this case I could two observations. In my job am reading the data from a flat file but to my surprise first observation of group data variables are missing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Sat, 25 Nov 2017 07:00:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/one-to-many-merge-data-issues/m-p/416124#M280174</guid>
      <dc:creator>hsigicherla</dc:creator>
      <dc:date>2017-11-25T07:00:22Z</dc:date>
    </item>
  </channel>
</rss>

