<?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: Merging in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merging/m-p/332807#M74947</link>
    <description>&lt;P&gt;Your variable &lt;EM&gt;conc&lt;/EM&gt; exists in both datasets but is not part of the by statement for the merge. In such a case the result dataset will contain the value of &lt;EM&gt;conc&lt;/EM&gt; of the last dataset where it exists (using the order as listed in the merge statement).&lt;/P&gt;
&lt;P&gt;The easiest way to get around this: rename your variables so that the names are unique; ie. &lt;EM&gt;conc_newd4, conc_newl4&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're after non-missing values from either dataset you then can use a &lt;EM&gt;coalesce()&lt;/EM&gt; function in the data step where you merge, ie.&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;conc=coalesce(conc_newd4, conc_newl4);&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;You will still have to decide what to do in a case where there is a &amp;nbsp;non-missing value in the same row for both&amp;nbsp;&lt;EM&gt;conc_newd4&lt;/EM&gt; and &lt;EM&gt;conc_newl4&lt;/EM&gt;.&lt;/P&gt;</description>
    <pubDate>Tue, 14 Feb 2017 21:53:00 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2017-02-14T21:53:00Z</dc:date>
    <item>
      <title>Merging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging/m-p/332804#M74946</link>
      <description>&lt;P&gt;I am using the following code to merge data sets newl4 and newd4 after they have been sorted by wsubj:&lt;/P&gt;&lt;P&gt;data all;&lt;BR /&gt;merge newl4(in=inp) newd4(in=ine);&lt;BR /&gt;by wsubj ;&lt;BR /&gt;if inp and ine;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;newd4&lt;/P&gt;&lt;P&gt;subj time cmt conc&lt;/P&gt;&lt;P&gt;1 0.25 1 0&lt;BR /&gt;1 0.25 2 0&lt;BR /&gt;1 0.25 3 0&lt;BR /&gt;1 0.25 4 0&lt;BR /&gt;1 0.25 5 0&lt;BR /&gt;1 0.25 6 0&lt;BR /&gt;1 0.25 7 0&lt;BR /&gt;1 0.25 8 0&lt;BR /&gt;1 0.25 9 0&lt;BR /&gt;1 0.25 10 0&lt;BR /&gt;1 0.25 11 0.2242009&lt;BR /&gt;1 0.25 12 0&lt;BR /&gt;1 0.25 13 0&lt;BR /&gt;1 0.25 14 0&lt;BR /&gt;1 0.25 15 0&lt;BR /&gt;1 0.25 16 0&lt;BR /&gt;1 0.25 17 0&lt;BR /&gt;1 0.25 18 0&lt;BR /&gt;1 0.25 19 0&lt;BR /&gt;1 0.25 20 0&lt;BR /&gt;1 0.25 21 0&lt;BR /&gt;1 0.25 22 0&lt;BR /&gt;1 0.25 23 0&lt;BR /&gt;1 0.25 24 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Newl4&lt;/P&gt;&lt;P&gt;subj time cmt conc&lt;/P&gt;&lt;P&gt;1 0.25 1 0&lt;BR /&gt;1 0.25 2 0&lt;BR /&gt;1 0.25 3 0&lt;BR /&gt;1 0.25 4 0&lt;BR /&gt;1 0.25 5 0&lt;BR /&gt;1 0.25 6 0&lt;BR /&gt;1 0.25 7 0&lt;BR /&gt;1 0.25 8 0&lt;BR /&gt;1 0.25 9 0&lt;BR /&gt;1 0.25 10 0&lt;BR /&gt;1 0.25 11 0&lt;BR /&gt;1 0.25 12 0&lt;BR /&gt;1 0.25 13 0&lt;BR /&gt;1 0.25 14 0&lt;BR /&gt;1 0.25 15 0&lt;BR /&gt;1 0.25 16 0&lt;BR /&gt;1 0.25 17 0&lt;BR /&gt;1 0.25 18 0&lt;BR /&gt;1 0.25 19 0&lt;BR /&gt;1 0.25 20 0&lt;BR /&gt;1 0.25 21 0&lt;BR /&gt;1 0.25 22 0&lt;BR /&gt;1 0.25 23 0.0960861&lt;/P&gt;&lt;P&gt;10.25 24 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The only difference between them is that newd5 and newl4 have a conc in different cmt(i.e., newd4-cmt 11 and newl4 cmt23).&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Whe I try to merge them I only get a value for conc in cmt 11 of 0.22, while cmt 23=0.&amp;nbsp; Can someone&amp;nbsp; give me&amp;nbsp;code that will result in both cmt11 and cmt23 showing the values in newd4 and newl4 in the merged data set all?&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2017 21:35:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging/m-p/332804#M74946</guid>
      <dc:creator>jacksonan123</dc:creator>
      <dc:date>2017-02-14T21:35:43Z</dc:date>
    </item>
    <item>
      <title>Re: Merging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging/m-p/332807#M74947</link>
      <description>&lt;P&gt;Your variable &lt;EM&gt;conc&lt;/EM&gt; exists in both datasets but is not part of the by statement for the merge. In such a case the result dataset will contain the value of &lt;EM&gt;conc&lt;/EM&gt; of the last dataset where it exists (using the order as listed in the merge statement).&lt;/P&gt;
&lt;P&gt;The easiest way to get around this: rename your variables so that the names are unique; ie. &lt;EM&gt;conc_newd4, conc_newl4&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're after non-missing values from either dataset you then can use a &lt;EM&gt;coalesce()&lt;/EM&gt; function in the data step where you merge, ie.&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;conc=coalesce(conc_newd4, conc_newl4);&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;You will still have to decide what to do in a case where there is a &amp;nbsp;non-missing value in the same row for both&amp;nbsp;&lt;EM&gt;conc_newd4&lt;/EM&gt; and &lt;EM&gt;conc_newl4&lt;/EM&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2017 21:53:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging/m-p/332807#M74947</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-02-14T21:53:00Z</dc:date>
    </item>
    <item>
      <title>Re: Merging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging/m-p/332895#M74974</link>
      <description>&lt;P&gt;If conc is always &amp;gt;= 0 in both datasets, then you can simply do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data all;
merge newl4(in=inp) newd4(in=ine rename=conc=conc2);
by subj ;
if inp and ine;
conc = max(conc, conc2);
drop conc2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Feb 2017 04:26:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging/m-p/332895#M74974</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-02-15T04:26:24Z</dc:date>
    </item>
    <item>
      <title>Re: Merging</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging/m-p/332936#M74985</link>
      <description>&lt;P&gt;The code worked very well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2017 10:34:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging/m-p/332936#M74985</guid>
      <dc:creator>jacksonan123</dc:creator>
      <dc:date>2017-02-15T10:34:32Z</dc:date>
    </item>
  </channel>
</rss>

