<?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: Updated non existing ID's from other table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Updated-non-existing-ID-s-from-other-table/m-p/540739#M149222</link>
    <description>&lt;P&gt;Another possibility is to use SORT and MERGE:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=lib1.table1;
  by id;
run;

proc sort data=lib2.table1;
  by id;
run;

data want;
  merge lib2.table1 lib1.table1;
  by id;
run;&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that I put lib2.table1 before lib1.table1 on the MERGE statement; that way, the data from LIB1 overwrites the data from LIB2 if both are present.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to do the same with more tables, just remember to put the tables with highest priority last in the MERGE statement.&lt;/P&gt;</description>
    <pubDate>Wed, 06 Mar 2019 11:44:08 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2019-03-06T11:44:08Z</dc:date>
    <item>
      <title>Updated non existing ID's from other table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updated-non-existing-ID-s-from-other-table/m-p/540669#M149189</link>
      <description>&lt;P&gt;Dear Experts,&lt;/P&gt;&lt;P&gt;I need to update the lib1.Table1 using another table where ID not in lib1.Table1 with corresponding columns (Same col name(30+ columns))&lt;/P&gt;&lt;P&gt;Each table in different library with the same table name and column name.&lt;/P&gt;&lt;P&gt;I want to group it out into single table with only unique IDs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data lib1.table1; /*need All unique ID in this table*/
input Id var1$ var2 var3 var4 ;/*....var30*/
cards;
111 a 1 5 9
12 v 4 5 3
32 b 1 8 4
54 b 1 3 7
78 f 9 7 8
;

data lib2.table1;
input Id var1$ var2 var3 var4 ;/*....var30*/
cards;
111 s 2 8 7
2 d 7 3 7
3 h 5 7 8
14 g 2 8 7
78 j 1 3 4
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;OP 

111 a 1 5 9
12 v 4 5 3
32 b 1 8 4
54 b 1 3 7
78 f 9 7 8
2 d 7 3 7
3 h 5 7 8
14 g 2 8 7&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please suggest some ideas to resolve it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Much Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2019 07:11:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updated-non-existing-ID-s-from-other-table/m-p/540669#M149189</guid>
      <dc:creator>Sathish_jammy</dc:creator>
      <dc:date>2019-03-06T07:11:29Z</dc:date>
    </item>
    <item>
      <title>Re: Updated non existing ID's from other table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updated-non-existing-ID-s-from-other-table/m-p/540671#M149191</link>
      <description>&lt;P&gt;Try a simple SQL approach:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select *
  from table1
union all
  select *
  from table2
  where id not in (select id from table1)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Mar 2019 07:18:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updated-non-existing-ID-s-from-other-table/m-p/540671#M149191</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-06T07:18:21Z</dc:date>
    </item>
    <item>
      <title>Re: Updated non existing ID's from other table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updated-non-existing-ID-s-from-other-table/m-p/540675#M149195</link>
      <description>&lt;P&gt;Like this? (I have changed a data set name to work with the data)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table1;
input Id var1$ var2 var3 var4 ;
cards;
111 a 1 5 9
12 v 4 5 3
32 b 1 8 4
54 b 1 3 7
78 f 9 7 8
;

data table2;
input Id var1$ var2 var3 var4 ;
cards;
111 s 2 8 7
2 d 7 3 7
3 h 5 7 8
14 g 2 8 7
78 j 1 3 4
;

proc sql;
   create table append as
   select * from table2
   where Id not in (select distinct Id from table1);
quit;

proc append base=table1 data=append;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Mar 2019 07:23:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updated-non-existing-ID-s-from-other-table/m-p/540675#M149195</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-03-06T07:23:18Z</dc:date>
    </item>
    <item>
      <title>Re: Updated non existing ID's from other table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updated-non-existing-ID-s-from-other-table/m-p/540702#M149205</link>
      <description>&lt;P&gt;Dear&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank u for your valuable codes...&lt;/P&gt;&lt;P&gt;What if... to join 10 more tables in the same method.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data lib1.table1;
input Id var1$ var2 var3 var4 ;/*....var30*/
cards;
111 a 1 5 9
12 v 4 5 3
32 b 1 8 4
54 b 1 3 7
78 f 9 7 8
;

data lib2.table1;
input Id var1$ var2 var3 var4 ;/*....var30*/
cards;
111 s 2 8 7
2 d 7 3 7
3 h 5 7 8
14 g 2 8 7
78 f 9 7 8
;
data lib3.table1;
input Id var1$ var2 var3 var4 ;/*....var30*/
cards;
78 g 3 9 5
12 j 4 8 4
43 l 5 7 6
414 w 6 6 8
378 t 7 5 0
;

/*lib10.table1*/&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Mar 2019 08:55:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updated-non-existing-ID-s-from-other-table/m-p/540702#M149205</guid>
      <dc:creator>Sathish_jammy</dc:creator>
      <dc:date>2019-03-06T08:55:13Z</dc:date>
    </item>
    <item>
      <title>Re: Updated non existing ID's from other table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updated-non-existing-ID-s-from-other-table/m-p/540708#M149210</link>
      <description>&lt;P&gt;Then you need to start with defining logic for special cases. What should happen when you have an id that is not yet in table1, but exists in parallel in more than one of the other tables? Which one should take precedence as the "new" item for the resulting table1?&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2019 09:12:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updated-non-existing-ID-s-from-other-table/m-p/540708#M149210</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-06T09:12:48Z</dc:date>
    </item>
    <item>
      <title>Re: Updated non existing ID's from other table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updated-non-existing-ID-s-from-other-table/m-p/540739#M149222</link>
      <description>&lt;P&gt;Another possibility is to use SORT and MERGE:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=lib1.table1;
  by id;
run;

proc sort data=lib2.table1;
  by id;
run;

data want;
  merge lib2.table1 lib1.table1;
  by id;
run;&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that I put lib2.table1 before lib1.table1 on the MERGE statement; that way, the data from LIB1 overwrites the data from LIB2 if both are present.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to do the same with more tables, just remember to put the tables with highest priority last in the MERGE statement.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2019 11:44:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updated-non-existing-ID-s-from-other-table/m-p/540739#M149222</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2019-03-06T11:44:08Z</dc:date>
    </item>
  </channel>
</rss>

