<?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: How do i adds records to an existing table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-adds-records-to-an-existing-table/m-p/676419#M203952</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/333513"&gt;@Angel_Larrion&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't actually need to create intermediate files with the TABLE variable.&amp;nbsp; All you have to do is append table2 to table1.&amp;nbsp; Then you can tell proc sort to place all table1 records prior to tied table2 records.&amp;nbsp; It's called the EQUALS option in proc sort.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data preneed /view=preneed;
  set table_a  table_b;
run;
proc sort data=preneed out=need EQUALS;
  by branch_id area card_group;
run;

data want;
  set need;
  by branch_id area card_group;
  if first.card_group;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I specified EQUALS in the proc sort above (as opposed to NOEQUALS).&amp;nbsp; But unless your system administrator did something pathological when installing SAS, it is the default for proc sort, so the option doesn't need to be specifically entered.&lt;/P&gt;</description>
    <pubDate>Thu, 13 Aug 2020 08:10:39 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2020-08-13T08:10:39Z</dc:date>
    <item>
      <title>How do i adds records to an existing table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-adds-records-to-an-existing-table/m-p/676311#M203913</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 2 tables:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Table A&lt;/U&gt;:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Branch_Id&lt;/TD&gt;&lt;TD&gt;Area&lt;/TD&gt;&lt;TD&gt;Card_group&lt;/TD&gt;&lt;TD&gt;Num_issued&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;171&lt;/TD&gt;&lt;TD&gt;220&lt;/TD&gt;&lt;TD&gt;Isracard Group&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;172&lt;/TD&gt;&lt;TD&gt;221&lt;/TD&gt;&lt;TD&gt;Leumi Group&lt;/TD&gt;&lt;TD&gt;22&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;172&lt;/TD&gt;&lt;TD&gt;221&lt;/TD&gt;&lt;TD&gt;Isracard Group&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;173&lt;/TD&gt;&lt;TD&gt;275&lt;/TD&gt;&lt;TD&gt;ICC Group&lt;/TD&gt;&lt;TD&gt;15&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Table B&lt;/U&gt;:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Branch_Id&lt;/TD&gt;&lt;TD&gt;Area&lt;/TD&gt;&lt;TD&gt;Card_group&lt;/TD&gt;&lt;TD&gt;Num_issued&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;171&lt;/TD&gt;&lt;TD&gt;220&lt;/TD&gt;&lt;TD&gt;Isracard Group&lt;/TD&gt;&lt;TD&gt;1237&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;172&lt;/TD&gt;&lt;TD&gt;223&lt;/TD&gt;&lt;TD&gt;Leumi Group&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;172&lt;/TD&gt;&lt;TD&gt;221&lt;/TD&gt;&lt;TD&gt;Isracard Group&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;14&lt;/TD&gt;&lt;TD&gt;199&lt;/TD&gt;&lt;TD&gt;ICC Group&lt;/TD&gt;&lt;TD&gt;211&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want that all the records in table A to appear in the final table plus the records in table B when the 3 fields (Branch_Id +&amp;nbsp; Area + Card_group)&amp;nbsp;do not exactly match to table A I want to Add the record of table B to table A.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If there is a match in 3 fields and only the field Num_issued is different, the record of table B will not be taken.&lt;BR /&gt;Example of the desired table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Final table&lt;/U&gt;:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Branch_Id&lt;/TD&gt;&lt;TD&gt;Area&lt;/TD&gt;&lt;TD&gt;Card_group&lt;/TD&gt;&lt;TD&gt;Num_issued&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;171&lt;/TD&gt;&lt;TD&gt;220&lt;/TD&gt;&lt;TD&gt;Isracard Group&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;172&lt;/TD&gt;&lt;TD&gt;221&lt;/TD&gt;&lt;TD&gt;Leumi Group&lt;/TD&gt;&lt;TD&gt;22&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;172&lt;/TD&gt;&lt;TD&gt;221&lt;/TD&gt;&lt;TD&gt;Isracard Group&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;172&lt;/TD&gt;&lt;TD&gt;223&lt;/TD&gt;&lt;TD&gt;Leumi Group&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;173&lt;/TD&gt;&lt;TD&gt;275&lt;/TD&gt;&lt;TD&gt;ICC Group&lt;/TD&gt;&lt;TD&gt;15&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;14&lt;/TD&gt;&lt;TD&gt;199&lt;/TD&gt;&lt;TD&gt;ICC Group&lt;/TD&gt;&lt;TD&gt;221&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Aug 2020 21:05:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-adds-records-to-an-existing-table/m-p/676311#M203913</guid>
      <dc:creator>shlomiohana</dc:creator>
      <dc:date>2020-08-12T21:05:45Z</dc:date>
    </item>
    <item>
      <title>Re: How do i adds records to an existing table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-adds-records-to-an-existing-table/m-p/676326#M203916</link>
      <description>&lt;P&gt;Doing this with SQL:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table TC as
select * 
from TB as a
where not exists (select * from TA where branch_id=a.branch_id and area=a.area and card_group=a.card_group);
insert into TA select * from TC;
drop table TC;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Aug 2020 21:38:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-adds-records-to-an-existing-table/m-p/676326#M203916</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-08-12T21:38:58Z</dc:date>
    </item>
    <item>
      <title>Re: How do i adds records to an existing table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-adds-records-to-an-existing-table/m-p/676385#M203939</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table_a;
set table_a;
table=1;
run;

data table_b;
set table_b;
table=2;
run;

data pre_want;
set table_a table_b;
run;

proc sort data=pre_want;
by Branch_Id 	Area	Card_group table; 
run;

data want;
set pre_want;
by Branch_Id  Area Card_group ;
if first.card_group=1 then output;&lt;BR /&gt;drop table;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Aug 2020 03:52:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-adds-records-to-an-existing-table/m-p/676385#M203939</guid>
      <dc:creator>Angel_Larrion</dc:creator>
      <dc:date>2020-08-13T03:52:10Z</dc:date>
    </item>
    <item>
      <title>Re: How do i adds records to an existing table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-adds-records-to-an-existing-table/m-p/676389#M203941</link>
      <description>&lt;P&gt;If both tables are sorted, then a MERGE is all you need:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT;
&amp;nbsp;&amp;nbsp;merge B A;   * The order matters: Keep A values rather than B values if both are found;
&amp;nbsp; by&amp;nbsp;Branch_Id Area Card_group;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2020 04:38:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-adds-records-to-an-existing-table/m-p/676389#M203941</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-08-13T04:38:37Z</dc:date>
    </item>
    <item>
      <title>Re: How do i adds records to an existing table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-adds-records-to-an-existing-table/m-p/676419#M203952</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/333513"&gt;@Angel_Larrion&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't actually need to create intermediate files with the TABLE variable.&amp;nbsp; All you have to do is append table2 to table1.&amp;nbsp; Then you can tell proc sort to place all table1 records prior to tied table2 records.&amp;nbsp; It's called the EQUALS option in proc sort.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data preneed /view=preneed;
  set table_a  table_b;
run;
proc sort data=preneed out=need EQUALS;
  by branch_id area card_group;
run;

data want;
  set need;
  by branch_id area card_group;
  if first.card_group;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I specified EQUALS in the proc sort above (as opposed to NOEQUALS).&amp;nbsp; But unless your system administrator did something pathological when installing SAS, it is the default for proc sort, so the option doesn't need to be specifically entered.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2020 08:10:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-adds-records-to-an-existing-table/m-p/676419#M203952</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-08-13T08:10:39Z</dc:date>
    </item>
  </channel>
</rss>

