<?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: Table A has missing data. Table B has data that is missing in table A. How to combine tables. in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Table-A-has-missing-data-Table-B-has-data-that-is-missing-in/m-p/580867#M17782</link>
    <description>&lt;P&gt;Looks like a straight forward application of the UPDATE statement.&amp;nbsp; TABLEB is your master table. TABLEA is your set of transactions to use to make the updates, some of which have missing values that will be ignored.&amp;nbsp; PERSONID is your key variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 update tableb tablea;
 by personid;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you only want to keep the person's listed in the transaction dataset then use the IN= option and a subsetting if.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 update tableb tablea(in=intrans);
 by personid;
 if intrans;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;PS&amp;nbsp; Not clear why some feel it is easier to post spreadsheets instead of data steps to show sample data. I find it much easier to type data into lines of text that navigate a spreadsheet. See the first reply to your question for an example.&lt;/P&gt;</description>
    <pubDate>Tue, 13 Aug 2019 15:56:13 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-08-13T15:56:13Z</dc:date>
    <item>
      <title>Table A has missing data. Table B has data that is missing in table A. How to combine tables.</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Table-A-has-missing-data-Table-B-has-data-that-is-missing-in/m-p/580819#M17779</link>
      <description>&lt;P&gt;Hello Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS 9.4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have missing data in Table A, and Table B contains that missing data. How do I go about taking data from Table B and populating it into Table A? I have attached an over-simplified Excel file to help visualize what I am talking about. Table A is the original data source, Table B is the data source I want to use to populate the missing data in Table A, and Table C is what I would like the end result to be.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To be more specific, I am missing some StudentID's from my original data source (Table A). I want to use another data source (Table B) to populate the missing StudentID's in Table A by using a shared column between the two tables, PersonID.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is what I have tried so far, and I don't think it's working as I want it to.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sort data=TableA out=TableA_sort;
     by PersonID;
run;

proc sort data=TableB out=TableB_sort;
     by PersonID;
run;

data TableC;
     merge TableA_sort (in=inTableA_sort)&lt;BR /&gt;           TableB_sort (in=inTableB_sort);&lt;BR /&gt;     by PersonID;
     if inTableA_sort=1 and inTableB_sort=1;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2019 14:26:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Table-A-has-missing-data-Table-B-has-data-that-is-missing-in/m-p/580819#M17779</guid>
      <dc:creator>bourdeax</dc:creator>
      <dc:date>2019-08-13T14:26:45Z</dc:date>
    </item>
    <item>
      <title>Re: Table A has missing data. Table B has data that is missing in table A. How to combine tables.</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Table-A-has-missing-data-Table-B-has-data-that-is-missing-in/m-p/580822#M17780</link>
      <description>&lt;P&gt;You're close &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;PRE&gt;&lt;CODE class=" language-sas"&gt;
data TableA;
input StudentID PersonID;
datalines;
. 32974
. 79961
. 76233
. 21620
12564 82765
64836 36324
63206 40631
74116 12069
67036 40832
47612 11502
;

data TableB;
input StudentID PersonID;
datalines;
24973 32974
91362 79961
10051 76233
19188 21620
;

proc sort data=TableA out=TableA_sort;
     by PersonID;
run;

proc sort data=TableB out=TableB_sort;
     by PersonID;
run;

data TableC;
     merge TableA_sort (in=inTableA_sort)
           TableB_sort (in=inTableB_sort);
     by PersonID;
run;
    &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Aug 2019 14:30:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Table-A-has-missing-data-Table-B-has-data-that-is-missing-in/m-p/580822#M17780</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-08-13T14:30:25Z</dc:date>
    </item>
    <item>
      <title>Re: Table A has missing data. Table B has data that is missing in table A. How to combine tables.</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Table-A-has-missing-data-Table-B-has-data-that-is-missing-in/m-p/580823#M17781</link>
      <description>&lt;P&gt;Or&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data TableC(drop=rc);
    if _N_=1 then do;
        declare hash h(dataset:'TableB');
        h.definekey('PersonID');
        h.definedata('StudentID');
        h.definedone();
    end;

    set TableA;

    rc=h.find();
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Aug 2019 14:32:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Table-A-has-missing-data-Table-B-has-data-that-is-missing-in/m-p/580823#M17781</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-08-13T14:32:26Z</dc:date>
    </item>
    <item>
      <title>Re: Table A has missing data. Table B has data that is missing in table A. How to combine tables.</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Table-A-has-missing-data-Table-B-has-data-that-is-missing-in/m-p/580867#M17782</link>
      <description>&lt;P&gt;Looks like a straight forward application of the UPDATE statement.&amp;nbsp; TABLEB is your master table. TABLEA is your set of transactions to use to make the updates, some of which have missing values that will be ignored.&amp;nbsp; PERSONID is your key variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 update tableb tablea;
 by personid;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you only want to keep the person's listed in the transaction dataset then use the IN= option and a subsetting if.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 update tableb tablea(in=intrans);
 by personid;
 if intrans;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;PS&amp;nbsp; Not clear why some feel it is easier to post spreadsheets instead of data steps to show sample data. I find it much easier to type data into lines of text that navigate a spreadsheet. See the first reply to your question for an example.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2019 15:56:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Table-A-has-missing-data-Table-B-has-data-that-is-missing-in/m-p/580867#M17782</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-08-13T15:56:13Z</dc:date>
    </item>
    <item>
      <title>Re: Table A has missing data. Table B has data that is missing in table A. How to combine tables.</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Table-A-has-missing-data-Table-B-has-data-that-is-missing-in/m-p/580906#M17783</link>
      <description>&lt;P&gt;Thanks for the response. I tried your method and got a dozen warnings stating "WARNING: The MASTER data set contains more than one observation for a BY group." As I am still relatively new to SAS, I am not sure what this means.. Your help is appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS&amp;nbsp;tomayto, tomahto in my opinion.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2019 17:35:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Table-A-has-missing-data-Table-B-has-data-that-is-missing-in/m-p/580906#M17783</guid>
      <dc:creator>bourdeax</dc:creator>
      <dc:date>2019-08-13T17:35:53Z</dc:date>
    </item>
    <item>
      <title>Re: Table A has missing data. Table B has data that is missing in table A. How to combine tables.</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Table-A-has-missing-data-Table-B-has-data-that-is-missing-in/m-p/580908#M17784</link>
      <description>&lt;P&gt;That means your table has multiple values STUDENT ids for the same PERSON id. Which also means that it is useless for your original purpose of using it as the source for the right value of STUDENT id to use to replace the missing values in TABLEA.&lt;BR /&gt;What value do you want to use when the person has multiple values?&lt;/P&gt;
&lt;P&gt;Perhaps there is some other variable like STATUS or DATE that you can use to filter it down to the one true value for STUDENT id per PERSON id?&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2019 18:02:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Table-A-has-missing-data-Table-B-has-data-that-is-missing-in/m-p/580908#M17784</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-08-13T18:02:47Z</dc:date>
    </item>
  </channel>
</rss>

