<?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: Set vs  Merge statements in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Set-vs-Merge-statements/m-p/684731#M207554</link>
    <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Here are some slides I did in a presentation to illustrate SET vs MERGE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SET:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_0-1600354584545.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49496iFDB18D9F5A7EBF11/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_0-1600354584545.png" alt="Cynthia_sas_0-1600354584545.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Simple MERGE&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_1-1600354626024.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49497i9D70255EBC0F3B60/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_1-1600354626024.png" alt="Cynthia_sas_1-1600354626024.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;all possible MERGE outputs:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_2-1600354731399.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49498i36F7B7D19F4A27F2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_2-1600354731399.png" alt="Cynthia_sas_2-1600354731399.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_4-1600354789787.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49500i066BA0D2AD843190/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_4-1600354789787.png" alt="Cynthia_sas_4-1600354789787.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I recommend nearly ALWAYS using a BY and IN= with MERGE to make sure you have complete control over the MERGE output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;</description>
    <pubDate>Thu, 17 Sep 2020 18:01:36 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2020-09-17T18:01:36Z</dc:date>
    <item>
      <title>Set vs  Merge statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-vs-Merge-statements/m-p/684549#M207467</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data m2m;
infile datalines;
input id$ x;
cards;
A25 24
A25 22
A25 76
;
run;

data m2m1;
infile datalines;
input id$ x;
cards;
A25 24
A25 22
A25 6
;
run;

data m2m3;
merge m2m m2m1;
proc print;
run;/*with out by variable*/

proc sort data =m2m1;
by id;
run;

proc sort data=m2m1;
by id;
run;


data m2m3;
merge m2m m2m1;
by id;
proc print;
run;/*with by variable*/

proc sort data =m2m1;
by id;
run;

proc sort data=m2m1;
by id;
run;

data s2s;
set m2m m2m1;
by id;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Here i using set and Merge statements&amp;nbsp; in set with by variable all obeservations came but merge with by variable second dataset over write in first dataset&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2020 11:26:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-vs-Merge-statements/m-p/684549#M207467</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2020-09-17T11:26:20Z</dc:date>
    </item>
    <item>
      <title>Re: Set vs  Merge statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-vs-Merge-statements/m-p/684551#M207469</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Here i using set and Merge statements&amp;nbsp; in set with by variable all obeservations came but merge with by variable second dataset over write in first dataset&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Yes, this is expected when you merge data sets with the exact same variable name in both data sets. What is your question?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2020 11:35:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-vs-Merge-statements/m-p/684551#M207469</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-09-17T11:35:41Z</dc:date>
    </item>
    <item>
      <title>Re: Set vs  Merge statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-vs-Merge-statements/m-p/684561#M207475</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;PaigeMiller&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using Merge with by variable second dataset overwrite first dataset&amp;nbsp;&lt;/P&gt;&lt;P&gt;why its happend&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2020 12:11:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-vs-Merge-statements/m-p/684561#M207475</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2020-09-17T12:11:57Z</dc:date>
    </item>
    <item>
      <title>Re: Set vs  Merge statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-vs-Merge-statements/m-p/684565#M207478</link>
      <description>&lt;P&gt;Since all variables appear in both datasets, the PDV (Program Data Vector) will have two variables, id and x.&lt;/P&gt;
&lt;P&gt;Since both datasets contain an equal number of observations with identical ud variables, both the MERGE with and without BY will have the same results:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;an observation from m2m is read, and its contents put into the PDV&lt;/LI&gt;
&lt;LI&gt;an observation from m2m1 is read, its contents overwriting the values in the PDV&lt;/LI&gt;
&lt;LI&gt;these values are written to the output&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;When SET with a BY is used, the data step will&amp;nbsp;&lt;EM&gt;interleave&lt;/EM&gt; the datasets, it reads one observation for an id value from m2m, writes it to the output, reads an observation for the same id from m2m1, and writes that. This is why you have 3 observations after the MERGE, but 6 after the SET.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2020 12:32:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-vs-Merge-statements/m-p/684565#M207478</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-17T12:32:42Z</dc:date>
    </item>
    <item>
      <title>Re: Set vs  Merge statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-vs-Merge-statements/m-p/684601#M207489</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265860"&gt;@BrahmanandaRao&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What result would you like to see instead of overwriting the data?&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2020 13:34:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-vs-Merge-statements/m-p/684601#M207489</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-09-17T13:34:34Z</dc:date>
    </item>
    <item>
      <title>Re: Set vs  Merge statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-vs-Merge-statements/m-p/684731#M207554</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Here are some slides I did in a presentation to illustrate SET vs MERGE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SET:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_0-1600354584545.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49496iFDB18D9F5A7EBF11/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_0-1600354584545.png" alt="Cynthia_sas_0-1600354584545.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Simple MERGE&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_1-1600354626024.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49497i9D70255EBC0F3B60/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_1-1600354626024.png" alt="Cynthia_sas_1-1600354626024.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;all possible MERGE outputs:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_2-1600354731399.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49498i36F7B7D19F4A27F2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_2-1600354731399.png" alt="Cynthia_sas_2-1600354731399.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_4-1600354789787.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49500i066BA0D2AD843190/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_4-1600354789787.png" alt="Cynthia_sas_4-1600354789787.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I recommend nearly ALWAYS using a BY and IN= with MERGE to make sure you have complete control over the MERGE output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2020 18:01:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-vs-Merge-statements/m-p/684731#M207554</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2020-09-17T18:01:36Z</dc:date>
    </item>
  </channel>
</rss>

