<?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: merge statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/merge-statement/m-p/800082#M314688</link>
    <description>Because of errors you made when copying the program, it's anybody's guess what the program will do.  Fix the mistakes so we can explain the correct program.  At a minimum, move the BY statement so it immediately follows the MERGE statement.  And change (in=1) to (in=a)</description>
    <pubDate>Fri, 04 Mar 2022 07:25:05 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2022-03-04T07:25:05Z</dc:date>
    <item>
      <title>merge statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-statement/m-p/800079#M314687</link>
      <description>&lt;PRE&gt;data hello;
     merge apple (in=1) orange (in=b);
     if weight~=1,
     by fruit_id;
     if a and b; 
     FORMAT size 10.4 price 5.4;
     if weight&amp;gt;20 OR price&amp;gt;30 then do:
     margin=20;
     end;
run;

&lt;/PRE&gt;&lt;P&gt;my questions what does if a and b means here and is its significance to the action of merging? does the merging only happen when the few lines of lf then else statement is true?&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 07:09:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-statement/m-p/800079#M314687</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2022-03-04T07:09:15Z</dc:date>
    </item>
    <item>
      <title>Re: merge statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-statement/m-p/800082#M314688</link>
      <description>Because of errors you made when copying the program, it's anybody's guess what the program will do.  Fix the mistakes so we can explain the correct program.  At a minimum, move the BY statement so it immediately follows the MERGE statement.  And change (in=1) to (in=a)</description>
      <pubDate>Fri, 04 Mar 2022 07:25:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-statement/m-p/800082#M314688</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2022-03-04T07:25:05Z</dc:date>
    </item>
    <item>
      <title>Re: merge statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-statement/m-p/800089#M314691</link>
      <description>&lt;PRE&gt;data hello;
     merge apple (in=a) orange (in=b);
     if weight~=1;
     by fruit_id;
     if a and b; 
     FORMAT size 10.4 price 5.4;
     if weight&amp;gt;20 OR price&amp;gt;30 then do;
     margin=20;
     end;
run;&lt;/PRE&gt;&lt;P&gt;fixed! thx&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 08:13:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-statement/m-p/800089#M314691</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2022-03-04T08:13:36Z</dc:date>
    </item>
    <item>
      <title>Re: merge statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-statement/m-p/800106#M314698</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if a and b;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is a so-called SUBSETTING IF that evaluates the variables a and b. These variables are defined in your MERGE statement and indicate which dataset(s) contributed data to the current iteration of the DATA step by having values of either 0 (false) or 1 (true).&lt;/P&gt;
&lt;P&gt;So all processing after this statement will only occur during any given iteration of the data step when both datasets have at least one observation with a matching fruit_id.&lt;/P&gt;
&lt;P&gt;The actual result of each iteration depends on the location of the weight and price variables, and the respective number of observations in the datasets for a given fruit_id.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 11:15:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-statement/m-p/800106#M314698</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-03-04T11:15:38Z</dc:date>
    </item>
    <item>
      <title>Re: merge statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-statement/m-p/800152#M314721</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; To help you get a handle on using the MERGE statement with the IN= option, consider these examples.&lt;/P&gt;
&lt;P&gt;Common merge example with 2 datasets:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_1-1646401901241.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/69145i950D9538B1974334/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_1-1646401901241.png" alt="Cynthia_sas_1-1646401901241.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;All possible output tables from merging 2 datasets:&lt;/P&gt;
&lt;P&gt;Code to make data and do merge:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mtable1;
  infile datalines;
  input commonvar amount;
  return;
  datalines;
11 115
13 315
14 415
16 615
;
run;

data mtable2;
  infile datalines;
  input commonvar name $ zip $;
return;
datalines;
10 Alicia 12345
11 Bryce 23456
12 Carolyn 34567
13 David 45678
14 Elsa 56789
15 Fern 67890
;
run;&lt;BR /&gt;&lt;BR /&gt;**&amp;nbsp;merge&amp;nbsp;with&amp;nbsp;all&amp;nbsp;possible&amp;nbsp;outputs;&lt;BR /&gt;data both oneonly twoonly allofone alloftwo allobs;&lt;BR /&gt;   merge mtable1(in=inone) mtable2(in=intwo);&lt;BR /&gt;   by commonvar;&lt;BR /&gt;   if inone then do;&lt;BR /&gt;      output allofone;&lt;BR /&gt;      if inone and intwo then output both;&lt;BR /&gt;      else if inone and not intwo then output oneonly;&lt;BR /&gt;   end;&lt;BR /&gt;   if intwo then do;&lt;BR /&gt;      output alloftwo;&lt;BR /&gt;      if intwo and not inone then output twoonly;&lt;BR /&gt;   end;&lt;BR /&gt;   if inone or intwo then output allobs;&lt;BR /&gt;run;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_0-1646401831948.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/69144iE1EF41B5407268D0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_0-1646401831948.png" alt="Cynthia_sas_0-1646401831948.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; We cover the MERGE statement in detail in our Programming 2 course.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 13:53:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-statement/m-p/800152#M314721</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2022-03-04T13:53:23Z</dc:date>
    </item>
  </channel>
</rss>

