<?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: Updating 2 million table from another 2 mio table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Updating-2-million-table-from-another-2-mio-table/m-p/524083#M142480</link>
    <description>Is table_a a sas dataset?</description>
    <pubDate>Wed, 02 Jan 2019 13:40:13 GMT</pubDate>
    <dc:creator>tomrvincent</dc:creator>
    <dc:date>2019-01-02T13:40:13Z</dc:date>
    <item>
      <title>Updating 2 million table from another 2 mio table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating-2-million-table-from-another-2-mio-table/m-p/524079#M142479</link>
      <description>&lt;P&gt;Hi experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a table named table_a with 2 million records. I want to update a column of table_a from another 2 millon rows table-&amp;nbsp; named table_b.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My query is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;update&amp;nbsp;table_a u&lt;BR /&gt;set BIRTH_PLACE=(select BIRTH_PLACE from table_b as n&lt;BR /&gt;where u.party_number=n.party_number)&lt;BR /&gt;where u.party_number in (select party_number from table_b);&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This query takes too much time and never ending. Do you have any suggestion how to update this table?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks,&lt;/P&gt;&lt;P&gt;Onur&lt;/P&gt;</description>
      <pubDate>Wed, 02 Jan 2019 13:11:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating-2-million-table-from-another-2-mio-table/m-p/524079#M142479</guid>
      <dc:creator>dincooo</dc:creator>
      <dc:date>2019-01-02T13:11:31Z</dc:date>
    </item>
    <item>
      <title>Re: Updating 2 million table from another 2 mio table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating-2-million-table-from-another-2-mio-table/m-p/524083#M142480</link>
      <description>Is table_a a sas dataset?</description>
      <pubDate>Wed, 02 Jan 2019 13:40:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating-2-million-table-from-another-2-mio-table/m-p/524083#M142480</guid>
      <dc:creator>tomrvincent</dc:creator>
      <dc:date>2019-01-02T13:40:13Z</dc:date>
    </item>
    <item>
      <title>Re: Updating 2 million table from another 2 mio table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating-2-million-table-from-another-2-mio-table/m-p/524084#M142481</link>
      <description>&lt;P&gt;These two datasets are Oracle tables and we have the right to see them at SAS EG.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Jan 2019 13:42:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating-2-million-table-from-another-2-mio-table/m-p/524084#M142481</guid>
      <dc:creator>dincooo</dc:creator>
      <dc:date>2019-01-02T13:42:08Z</dc:date>
    </item>
    <item>
      <title>Re: Updating 2 million table from another 2 mio table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating-2-million-table-from-another-2-mio-table/m-p/524090#M142483</link>
      <description>Then I'd suggest doing the update with a macro loop, one record at a time (1st step in the loop would be to pick minimum party number greater than previously selected party number). At least that would not be 'never ending'.</description>
      <pubDate>Wed, 02 Jan 2019 14:20:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating-2-million-table-from-another-2-mio-table/m-p/524090#M142483</guid>
      <dc:creator>tomrvincent</dc:creator>
      <dc:date>2019-01-02T14:20:09Z</dc:date>
    </item>
    <item>
      <title>Re: Updating 2 million table from another 2 mio table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating-2-million-table-from-another-2-mio-table/m-p/524108#M142489</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the answer. If it is possible can you please write the code that does like this?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Jan 2019 15:06:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating-2-million-table-from-another-2-mio-table/m-p/524108#M142489</guid>
      <dc:creator>dincooo</dc:creator>
      <dc:date>2019-01-02T15:06:11Z</dc:date>
    </item>
    <item>
      <title>Re: Updating 2 million table from another 2 mio table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating-2-million-table-from-another-2-mio-table/m-p/524126#M142494</link>
      <description>&lt;P&gt;Alternatively -&lt;/P&gt;
&lt;P&gt;1) Load both tables, ID and the variable to update, into sas;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) Run update in SAS. If ID relation between tables is 1:1 or 1:N (not many to many)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; then better use data step with merge or update staement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;It will be much faster then SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3) Update Oracle table from sas result table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; You can use obs and firstobs option2 to manage update part by part.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; (step 1: obs=1000; step 2:&amp;nbsp; firstobs=1001 obs=1000, step 3: obs=2001 obs=1000, etc.)&lt;/P&gt;</description>
      <pubDate>Wed, 02 Jan 2019 16:20:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating-2-million-table-from-another-2-mio-table/m-p/524126#M142494</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2019-01-02T16:20:20Z</dc:date>
    </item>
    <item>
      <title>Re: Updating 2 million table from another 2 mio table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating-2-million-table-from-another-2-mio-table/m-p/524228#M142535</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your comment can you please write the code that does the last step?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jan 2019 06:47:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating-2-million-table-from-another-2-mio-table/m-p/524228#M142535</guid>
      <dc:creator>dincooo</dc:creator>
      <dc:date>2019-01-03T06:47:06Z</dc:date>
    </item>
    <item>
      <title>Re: Updating 2 million table from another 2 mio table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Updating-2-million-table-from-another-2-mio-table/m-p/524300#M142566</link>
      <description>&lt;P&gt;I have no oracle environment, now, to check my code.&lt;/P&gt;
&lt;P&gt;Here is a skeleton to adapt to your environment and needs.&lt;/P&gt;
&lt;P&gt;Code should run on sas with access to oracle:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* step 1 - define connection parameters */
LIBNAME DBCON ORACLE USER=&amp;amp;UserNm PASS=&amp;amp;PassWd PATH='EDWP' SCHEMA=IDWE CONNECTION=GLOBAL;

/* step 2 - load tables from oracle, relevant variables only */
PROC SQL;
	connect using DBCON;
        select * from connection to oracle
            (create table1 as
                select party_number, birth_place from table_a);
            (create table2 as
                select party_number, birth_place from table_b);
    disconnect from oracle; 
quit;

/* sort tables in sas, prepared to create updated table3 */

proc sort data=table1; by party_number; run;
proc sort data=table2; by party_number; run;

data table3; 
  merge table1(in=in1 rename=(birth_date=bd))
             table2(in=in2);  
    by party_number;
         /* keep observation only those in both tables and date differ */
         if in1 and in2 and birth_date ne bd;
         drop bd;
run;

/* Check table3 is birth_date updated as desired !!! */
/* check log - is updated observations count logic */

PROC SQL;
	connect using DBCON;
	select *  from connection to oracle   	
            (update table_a as a   from table3 as n
              set a.BIRTH_PLACE=n.birth_date
              where a.party_number = n.party_number
             );

    disconnect from oracle; 
quit;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By keeping only those observations in both tables and with different birth dates,&lt;/P&gt;
&lt;P&gt;you eliminate number of observations to update and save time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE - check table3 before trying update oracle table.&lt;/P&gt;
&lt;P&gt;Continue only if you accept the results.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jan 2019 15:46:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Updating-2-million-table-from-another-2-mio-table/m-p/524300#M142566</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2019-01-03T15:46:00Z</dc:date>
    </item>
  </channel>
</rss>

