<?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: what's wrong with my match merge: in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/what-s-wrong-with-my-match-merge/m-p/297966#M62614</link>
    <description>&lt;P&gt;The values for STATE_NAME get read only once, from each source of data. &amp;nbsp;So on the first observation per StateID, the STATE_NAME always comes from TWO, as the values from TWO overwrite the values from ONE. &amp;nbsp;But after the first observation per StateID, the values from ONE are read in and no longer get overwritten by values from TWO. &amp;nbsp;So the simple solution would be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data three;&lt;/P&gt;
&lt;P&gt;merge one (drop=state_name) two;&lt;/P&gt;
&lt;P&gt;by stateID;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
    <pubDate>Tue, 13 Sep 2016 10:44:55 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2016-09-13T10:44:55Z</dc:date>
    <item>
      <title>what's wrong with my match merge:</title>
      <link>https://communities.sas.com/t5/SAS-Programming/what-s-wrong-with-my-match-merge/m-p/297943#M62610</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;
&lt;P&gt;I have two datasets, in dataset one, I have some states with state id(stateid) but vacant state name(statename). In dataset two, I have only two variables: state id(stataid), state name(statename), and all stateid and statename are not vacant, I sort both dataset by stateid and merge the two, my code is as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data three;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; merge one two;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by stateid;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;
&lt;P&gt;but&amp;nbsp; I still have the same vacant state names!&lt;/P&gt;
&lt;P&gt;What's wrong with my code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks a lot!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2016 08:28:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/what-s-wrong-with-my-match-merge/m-p/297943#M62610</guid>
      <dc:creator>owenwqp1</dc:creator>
      <dc:date>2016-09-13T08:28:59Z</dc:date>
    </item>
    <item>
      <title>Re: what's wrong with my match merge:</title>
      <link>https://communities.sas.com/t5/SAS-Programming/what-s-wrong-with-my-match-merge/m-p/297945#M62611</link>
      <description>&lt;P&gt;When you have same variable (state name) on both data sets, only one takes place in output.&lt;/P&gt;&lt;P&gt;You can either drop the vacant sate name or use update instead merge, where the second data set&lt;/P&gt;&lt;P&gt;updates variables from the first one.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2016 08:43:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/what-s-wrong-with-my-match-merge/m-p/297945#M62611</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-09-13T08:43:01Z</dc:date>
    </item>
    <item>
      <title>Re: what's wrong with my match merge:</title>
      <link>https://communities.sas.com/t5/SAS-Programming/what-s-wrong-with-my-match-merge/m-p/297948#M62612</link>
      <description>&lt;P&gt;Let's dig a little into the workings of the data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
infile cards truncover;
input state_id state_name $;
cards;
1 
1 
2 
2 
3 
;
run;

data have2;
infile cards truncover;
input state_id state_name $;
cards;
1 NY
2 CA
2 CA
3 FL
;
run;

data want;
merge have1 have2;
by state_id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When the third data step is compiled, SAS looks at the structure of the contributing datasets, and creates a PDV (program data vector) with the variables state_id and state_name.&lt;/P&gt;
&lt;P&gt;When the data step executes its first iteration, data is read from have1, resulting in an empty state_name; next, data from have2 is read (as state_id matches), and state_name is set to "NY". Data is output.&lt;/P&gt;
&lt;P&gt;Then, in the second iteration, a matching record from have1 is read, once again state_name is set to empty; since no further matching record is present in have2, no data is read from there, and therefore the empty state_name is written to the ouput.&lt;/P&gt;
&lt;P&gt;With state_id=2 I deliberately inserted a second record in have2, and since a second matching read from have2 can be performed, the value "CA" is set for both empty records in have1.&lt;/P&gt;
&lt;P&gt;A proper merge would look like that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
merge
  have1
  have2 (rename=(state_name=new_state_name))
;
by state_id;
if state_name = ' ' then state_name = new_state_name;
drop new_state_name;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: took care of improper code formatting and typos&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2016 09:13:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/what-s-wrong-with-my-match-merge/m-p/297948#M62612</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-09-13T09:13:57Z</dc:date>
    </item>
    <item>
      <title>Re: what's wrong with my match merge:</title>
      <link>https://communities.sas.com/t5/SAS-Programming/what-s-wrong-with-my-match-merge/m-p/297966#M62614</link>
      <description>&lt;P&gt;The values for STATE_NAME get read only once, from each source of data. &amp;nbsp;So on the first observation per StateID, the STATE_NAME always comes from TWO, as the values from TWO overwrite the values from ONE. &amp;nbsp;But after the first observation per StateID, the values from ONE are read in and no longer get overwritten by values from TWO. &amp;nbsp;So the simple solution would be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data three;&lt;/P&gt;
&lt;P&gt;merge one (drop=state_name) two;&lt;/P&gt;
&lt;P&gt;by stateID;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2016 10:44:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/what-s-wrong-with-my-match-merge/m-p/297966#M62614</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-09-13T10:44:55Z</dc:date>
    </item>
  </channel>
</rss>

