<?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 Table A and Table B by ID: replacing blank columns in Table A with column value from Tab in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merging-Table-A-and-Table-B-by-ID-replacing-blank-columns-in/m-p/814774#M321608</link>
    <description>There is a simple way to do this as long as the non-missing values for a particular UniqueID in Table 2 ALWAYS match the non-missing values in Table 1 (and if each table only has one row per Unique_ID). This appears to be the case from the data you have shared. E.g., subject JM_909 has the same non-missing values for Var4, Var5, and Var6 in both tables.&lt;BR /&gt;You might remember that a MERGE in a data set the values in the right-hand table overwrite the values in the left-hand table for the matched observations that are defined with the BY statement. You would first need to sort each data set by Unique_ID and then&lt;BR /&gt;&lt;BR /&gt;Data Want;&lt;BR /&gt;merge Table1 Table2; /*For each value of UNIQUE_ID where the same variable exists in both tables, the value from Table2 will overwrite the value in Table1.*/&lt;BR /&gt;by Unique_ID;&lt;BR /&gt;run;&lt;BR /&gt;</description>
    <pubDate>Mon, 23 May 2022 19:17:30 GMT</pubDate>
    <dc:creator>svh</dc:creator>
    <dc:date>2022-05-23T19:17:30Z</dc:date>
    <item>
      <title>Merging Table A and Table B by ID: replacing blank columns in Table A with column value from Table B</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-Table-A-and-Table-B-by-ID-replacing-blank-columns-in/m-p/814358#M321434</link>
      <description>&lt;P&gt;Hi Experts!&lt;/P&gt;&lt;P&gt;I need some help merging two tables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table A is a large dataset with 400+ columns and over 31,000 rows. Table B is smaller and shares some of the same columns (9) and rows (1600+) as Table A.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Both tables share a unique ID (unique_id) - I need to impute values from table B in to the corresponding missing field in table A by unique_id.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here’s an example of what I want to do:&lt;/P&gt;&lt;P&gt;Table A&lt;/P&gt;&lt;P&gt;Unique_ID Var1 Var2 Var3 Var4 Var5 Var6……. Var400&lt;/P&gt;&lt;P&gt;MA_345 &amp;nbsp;&amp;nbsp;3 &amp;nbsp;&amp;nbsp;1 &amp;nbsp;19&amp;nbsp; 37.9 &amp;nbsp;&amp;nbsp;60&amp;nbsp; &amp;nbsp;77&lt;/P&gt;&lt;P&gt;JM_909&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;. &amp;nbsp;&amp;nbsp;&amp;nbsp;. &amp;nbsp;&amp;nbsp;&amp;nbsp;. &amp;nbsp;&amp;nbsp;40.2 &amp;nbsp;&amp;nbsp;55 &amp;nbsp;&amp;nbsp;67&lt;/P&gt;&lt;P&gt;TV_647&amp;nbsp; &amp;nbsp;1 &amp;nbsp;&amp;nbsp;. &amp;nbsp;&amp;nbsp;. &amp;nbsp;&amp;nbsp;37.7&amp;nbsp; &amp;nbsp;62 &amp;nbsp;&amp;nbsp;83&lt;/P&gt;&lt;P&gt;ED_331 &amp;nbsp;&amp;nbsp;7 &amp;nbsp;&amp;nbsp;5 &amp;nbsp;&amp;nbsp;. 38.0 &amp;nbsp;&amp;nbsp;65&amp;nbsp; &amp;nbsp;88&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table 2&lt;/P&gt;&lt;P&gt;Unique_ID Var1 Var2 Var3 Var4 Var5 Var6&lt;/P&gt;&lt;P&gt;JM_909&amp;nbsp; &amp;nbsp;3 &amp;nbsp;&amp;nbsp;&amp;nbsp;1 &amp;nbsp;&amp;nbsp;10 &amp;nbsp;&amp;nbsp;40.2 &amp;nbsp;&amp;nbsp;55 &amp;nbsp;&amp;nbsp;67&lt;/P&gt;&lt;P&gt;TV_647&amp;nbsp; &amp;nbsp;1 &amp;nbsp;&amp;nbsp;0 &amp;nbsp;&amp;nbsp;15 &amp;nbsp;&amp;nbsp;37.7&amp;nbsp; &amp;nbsp;62 &amp;nbsp;&amp;nbsp;83&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Result&lt;/P&gt;&lt;P&gt;Unique_ID Var1 Var2 Var3 Var4 Var5 Var6……. Var400&lt;/P&gt;&lt;P&gt;MA_345 &amp;nbsp;&amp;nbsp;3 &amp;nbsp;&amp;nbsp;1 &amp;nbsp;19&amp;nbsp; 37.9 &amp;nbsp;&amp;nbsp;60&amp;nbsp; &amp;nbsp;77&lt;/P&gt;&lt;P&gt;JM_909&amp;nbsp; &amp;nbsp;3 &amp;nbsp;&amp;nbsp;&amp;nbsp;1 &amp;nbsp;&amp;nbsp;10 &amp;nbsp;&amp;nbsp;40.2 &amp;nbsp;&amp;nbsp;55 &amp;nbsp;&amp;nbsp;67&lt;/P&gt;&lt;P&gt;TV_647&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; 0 &amp;nbsp;&amp;nbsp;15 &amp;nbsp;&amp;nbsp;37.7&amp;nbsp; &amp;nbsp;62 &amp;nbsp;&amp;nbsp;83&lt;/P&gt;&lt;P&gt;ED_331 &amp;nbsp;&amp;nbsp;7&amp;nbsp; &amp;nbsp; 5 &amp;nbsp;&amp;nbsp;.&amp;nbsp; &amp;nbsp; 38.0 &amp;nbsp;&amp;nbsp;65&amp;nbsp; &amp;nbsp;88&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help or guidance on this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 19 May 2022 20:09:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-Table-A-and-Table-B-by-ID-replacing-blank-columns-in/m-p/814358#M321434</guid>
      <dc:creator>mjalvarez</dc:creator>
      <dc:date>2022-05-19T20:09:58Z</dc:date>
    </item>
    <item>
      <title>Re: Merging Table A and Table B by ID: replacing blank columns in Table A with column value from Tab</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-Table-A-and-Table-B-by-ID-replacing-blank-columns-in/m-p/814774#M321608</link>
      <description>There is a simple way to do this as long as the non-missing values for a particular UniqueID in Table 2 ALWAYS match the non-missing values in Table 1 (and if each table only has one row per Unique_ID). This appears to be the case from the data you have shared. E.g., subject JM_909 has the same non-missing values for Var4, Var5, and Var6 in both tables.&lt;BR /&gt;You might remember that a MERGE in a data set the values in the right-hand table overwrite the values in the left-hand table for the matched observations that are defined with the BY statement. You would first need to sort each data set by Unique_ID and then&lt;BR /&gt;&lt;BR /&gt;Data Want;&lt;BR /&gt;merge Table1 Table2; /*For each value of UNIQUE_ID where the same variable exists in both tables, the value from Table2 will overwrite the value in Table1.*/&lt;BR /&gt;by Unique_ID;&lt;BR /&gt;run;&lt;BR /&gt;</description>
      <pubDate>Mon, 23 May 2022 19:17:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-Table-A-and-Table-B-by-ID-replacing-blank-columns-in/m-p/814774#M321608</guid>
      <dc:creator>svh</dc:creator>
      <dc:date>2022-05-23T19:17:30Z</dc:date>
    </item>
    <item>
      <title>Re: Merging Table A and Table B by ID: replacing blank columns in Table A with column value from Tab</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-Table-A-and-Table-B-by-ID-replacing-blank-columns-in/m-p/814791#M321618</link>
      <description>&lt;P&gt;You might want to do an UPDATE.&amp;nbsp; But you seem to want the reverse of the normal case it was designed to support.&amp;nbsp; The UPDATE statement is designed to apply transactions to an existing dataset.&amp;nbsp; Any missing value in the transaction dataset is ignored so the existing value is unchanged.&amp;nbsp; So the non-missing values in the transaction dataset "win".&amp;nbsp; You appear to want the reverse, where the non missing values in the original dataset "win".&amp;nbsp; So just treat the transactions as the original dataset and original dataset as the transactions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  update table2 tableA;
  by unique_id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 May 2022 20:29:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-Table-A-and-Table-B-by-ID-replacing-blank-columns-in/m-p/814791#M321618</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-23T20:29:56Z</dc:date>
    </item>
  </channel>
</rss>

