<?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 datasets without replacing missing data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-without-replacing-missing-data/m-p/858079#M339025</link>
    <description>&lt;P&gt;I should rephrase: I'm not sure what happened to these observations. The listed variables are common to both datasets with one exception: TESTA had no Btest variable, and TESTB had no Atest variable. The resulting dataset does have observations with entries for both tests, as well as those with entries in only one test or the other, but other observations were dropped entirely and I've no idea how to do the detective work. Here's the code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA TESTCHECK;&lt;BR /&gt;RETAIN Client_ID Site_Type Reporting_Month Reporting_Quarter Reporting_Year Year_of_Birth Race Ethnicity Gender Atest Btest;&lt;BR /&gt;IF 0 THEN SET TESTA TESTB;&lt;BR /&gt;CALL missing (of _all_);&lt;BR /&gt;MERGE TESTA TESTB;&lt;BR /&gt;BY Client_ID Reporting_Month;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate your help!&lt;/P&gt;</description>
    <pubDate>Thu, 09 Feb 2023 16:16:57 GMT</pubDate>
    <dc:creator>newtriks</dc:creator>
    <dc:date>2023-02-09T16:16:57Z</dc:date>
    <item>
      <title>Merging datasets without replacing missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-without-replacing-missing-data/m-p/845753#M334351</link>
      <description>&lt;P&gt;I'm trying to merge two datasets in which the same patient may have been tested once for TEST1 and twice&amp;nbsp; for TEST2.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So if the observations/variables are as follows:&lt;/P&gt;&lt;P&gt;FIRST DATASET&lt;/P&gt;&lt;P&gt;Obs&amp;nbsp; &amp;nbsp; &amp;nbsp;ID&amp;nbsp; &amp;nbsp; TEST1&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A&amp;nbsp; &amp;nbsp; &amp;nbsp;POS&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SECOND DATASET&lt;/P&gt;&lt;P&gt;Obs&amp;nbsp; &amp;nbsp; &amp;nbsp;ID&amp;nbsp; &amp;nbsp; TEST2&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A&amp;nbsp; &amp;nbsp; &amp;nbsp;POS&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A&amp;nbsp; &amp;nbsp; &amp;nbsp; POS&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The resulting merged set returns this:&lt;/P&gt;&lt;P&gt;Obs&amp;nbsp; &amp;nbsp; &amp;nbsp;ID&amp;nbsp; &amp;nbsp;TEST1&amp;nbsp; &amp;nbsp; TEST2&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A&amp;nbsp; &amp;nbsp; &amp;nbsp;POS&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; POS&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A&amp;nbsp; &amp;nbsp; &amp;nbsp;POS&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; POS&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I keep the second observation for this patient blank for TEST1?&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2022 19:10:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-without-replacing-missing-data/m-p/845753#M334351</guid>
      <dc:creator>newtriks</dc:creator>
      <dc:date>2022-11-22T19:10:36Z</dc:date>
    </item>
    <item>
      <title>Re: Merging datasets without replacing missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-without-replacing-missing-data/m-p/845757#M334352</link>
      <description>&lt;P&gt;A simple Merge will do &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: Did not catch the missing test1 part first.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input ID $ TEST1 $;
datalines;
A POS 
;

data two;
input ID $ TEST2 $;
datalines;
A POS 
A POS 
;

data want;
   if 0 then set one two;
   test1 = '';
   merge one two;
   by ID;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;
&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Result:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ID TEST1 TEST2
A  POS   POS
A        POS&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2022 19:43:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-without-replacing-missing-data/m-p/845757#M334352</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-11-22T19:43:13Z</dc:date>
    </item>
    <item>
      <title>Re: Merging datasets without replacing missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-without-replacing-missing-data/m-p/845758#M334353</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
if 0 then set first second; /* only here to populate the PDV */
call missing (of _all_);
merge
  first
  second
;
by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Nov 2022 19:39:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-without-replacing-missing-data/m-p/845758#M334353</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-11-22T19:39:41Z</dc:date>
    </item>
    <item>
      <title>Re: Merging datasets without replacing missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-without-replacing-missing-data/m-p/845760#M334354</link>
      <description>&lt;P&gt;Thanks. Perhaps I should have been clearer. These datasets have been imported from Excel, and each has over 2,000 observations. Is there a method which doesn't require manual data entry? I am much obliged.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2022 19:41:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-without-replacing-missing-data/m-p/845760#M334354</guid>
      <dc:creator>newtriks</dc:creator>
      <dc:date>2022-11-22T19:41:21Z</dc:date>
    </item>
    <item>
      <title>Re: Merging datasets without replacing missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-without-replacing-missing-data/m-p/845761#M334355</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;two initial data steps are just there to create data for the third data step. Instead of the two fake datasets created here, use your datasets in the MERGE statement.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2022 19:44:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-without-replacing-missing-data/m-p/845761#M334355</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-11-22T19:44:24Z</dc:date>
    </item>
    <item>
      <title>Re: Merging datasets without replacing missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-without-replacing-missing-data/m-p/845764#M334357</link>
      <description>&lt;P&gt;That did the trick. Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2022 20:11:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-without-replacing-missing-data/m-p/845764#M334357</guid>
      <dc:creator>newtriks</dc:creator>
      <dc:date>2022-11-22T20:11:12Z</dc:date>
    </item>
    <item>
      <title>Re: Merging datasets without replacing missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-without-replacing-missing-data/m-p/857790#M338945</link>
      <description>&lt;P&gt;Sorry to be responding after 2 months but it appears that this bit of code results in the deletion of any observations with both tests. Final dataset shows only those exclusive to one test variable or the other. I'm lost as to how to fix it. Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2023 16:48:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-without-replacing-missing-data/m-p/857790#M338945</guid>
      <dc:creator>newtriks</dc:creator>
      <dc:date>2023-02-08T16:48:49Z</dc:date>
    </item>
    <item>
      <title>Re: Merging datasets without replacing missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-without-replacing-missing-data/m-p/857937#M338984</link>
      <description>&lt;P&gt;Post examples for your datasets as data steps with datalines (as we have done) and your merge code.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2023 06:05:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-without-replacing-missing-data/m-p/857937#M338984</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-02-09T06:05:11Z</dc:date>
    </item>
    <item>
      <title>Re: Merging datasets without replacing missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-without-replacing-missing-data/m-p/858079#M339025</link>
      <description>&lt;P&gt;I should rephrase: I'm not sure what happened to these observations. The listed variables are common to both datasets with one exception: TESTA had no Btest variable, and TESTB had no Atest variable. The resulting dataset does have observations with entries for both tests, as well as those with entries in only one test or the other, but other observations were dropped entirely and I've no idea how to do the detective work. Here's the code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA TESTCHECK;&lt;BR /&gt;RETAIN Client_ID Site_Type Reporting_Month Reporting_Quarter Reporting_Year Year_of_Birth Race Ethnicity Gender Atest Btest;&lt;BR /&gt;IF 0 THEN SET TESTA TESTB;&lt;BR /&gt;CALL missing (of _all_);&lt;BR /&gt;MERGE TESTA TESTB;&lt;BR /&gt;BY Client_ID Reporting_Month;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate your help!&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2023 16:16:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-without-replacing-missing-data/m-p/858079#M339025</guid>
      <dc:creator>newtriks</dc:creator>
      <dc:date>2023-02-09T16:16:57Z</dc:date>
    </item>
    <item>
      <title>Re: Merging datasets without replacing missing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-without-replacing-missing-data/m-p/858151#M339056</link>
      <description>&lt;P&gt;UPDATE - got it to work. All good here. Thanks for responding.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2023 22:26:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-datasets-without-replacing-missing-data/m-p/858151#M339056</guid>
      <dc:creator>newtriks</dc:creator>
      <dc:date>2023-02-09T22:26:21Z</dc:date>
    </item>
  </channel>
</rss>

