<?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: update SAS tables Faster! in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Update-DBMS-tables-faster-from-SAS/m-p/386178#M92463</link>
    <description>&lt;P&gt;It has different techniques based on what you need to do&amp;nbsp;&lt;/P&gt;&lt;P&gt;suppose you want to update join from table_1 column party_name from table_2 column customer_name&amp;nbsp;&lt;/P&gt;&lt;P&gt;where party_number = customer_number&amp;nbsp;&lt;/P&gt;&lt;P&gt;and party_date_of_birth is missing&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First create view on table_1 say table_1_view on db say SQL server or Oracle&lt;/P&gt;&lt;P&gt;create view &lt;SPAN&gt;table_1_view&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;as&lt;/P&gt;&lt;P&gt;SELECT party_number, party_name&amp;nbsp;&lt;/P&gt;&lt;P&gt;From &amp;nbsp; &amp;nbsp; &amp;nbsp; Table_1&amp;nbsp;&lt;/P&gt;&lt;P&gt;where &amp;nbsp; &amp;nbsp; &amp;nbsp;party_date_of_birth is null;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in SAS&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc SQL;&lt;/P&gt;&lt;P&gt;create table work.table_1_view_update as&amp;nbsp;&lt;/P&gt;&lt;P&gt;SELECT party_number , customer_name as party_name /* this alias for the hash */&lt;/P&gt;&lt;P&gt;FROM &amp;lt;DB_libname&amp;gt;.table_1_view a inner join&amp;nbsp;&lt;SPAN&gt;&amp;lt;DB_libname&amp;gt;.table_2 b&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;on b.customer_number = a.party_number&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;;Quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;now work.table_1_view has the update we need&amp;nbsp;&lt;/P&gt;&lt;P&gt;let's use the hash to update&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data &lt;STRONG&gt;&amp;lt;DB_libname&amp;gt;.table_1_view&lt;/STRONG&gt;;&lt;BR /&gt;if _n_=1 then do;&lt;BR /&gt;declare hash ud(dataset:'&lt;SPAN&gt;work.table_1_view_update&lt;/SPAN&gt;');&lt;BR /&gt;ud.defineKey('party_number');&lt;BR /&gt;ud.defineData('party_name');&lt;BR /&gt;ud.defineDone();&lt;BR /&gt;end;&lt;BR /&gt;modify &lt;STRONG&gt;&amp;lt;DB_libname&amp;gt;.table_1_view&lt;/STRONG&gt;;&lt;BR /&gt;rcUpdate = ud.find();&lt;BR /&gt;if rcUpdate=0 then replace;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i hope this helps&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 08 Aug 2017 06:30:12 GMT</pubDate>
    <dc:creator>Amahareek</dc:creator>
    <dc:date>2017-08-08T06:30:12Z</dc:date>
    <item>
      <title>Update DBMS tables faster from SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-DBMS-tables-faster-from-SAS/m-p/385899#M92369</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;as update is too slow in SAS Proc SQL&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;we found a faster way to update big tables in a very fast way using hash and database views&amp;nbsp;&lt;/P&gt;&lt;P&gt;it's known that:&lt;/P&gt;&lt;P&gt;1- if you update in database view you will update the physical table&amp;nbsp;&lt;/P&gt;&lt;P&gt;2- hash update uses the memory (RAM) which might be slower if tables are very big.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;our solution is based on creating a view for all condition you want in the update statement in the view like&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;simple solution:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;UPDATE TABLE_A SET COLUMN_1 = {VALUE} WHERE condition_1 , condition_2&amp;nbsp;&lt;/P&gt;&lt;P&gt;;QUIT;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;our solution&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;create view as select column_1 from table_a where condition_1, condition_2&amp;nbsp;&lt;/P&gt;&lt;P&gt;then use the simple hash update which uses less memory ,faster update&amp;nbsp;&lt;/P&gt;&lt;P&gt;happy faster hash update&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Abdelrahman Mahareek&lt;/P&gt;&lt;P&gt;AML Technical Consultant&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2017 07:03:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-DBMS-tables-faster-from-SAS/m-p/385899#M92369</guid>
      <dc:creator>Amahareek</dc:creator>
      <dc:date>2017-08-09T07:03:06Z</dc:date>
    </item>
    <item>
      <title>Re: update SAS tables Faster!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-DBMS-tables-faster-from-SAS/m-p/385924#M92380</link>
      <description>&lt;P&gt;Very interestiung. Can you tell us more? For example:&lt;/P&gt;
&lt;P&gt;Which database and version?&lt;/P&gt;
&lt;P&gt;Where are the view and hash table created?&lt;/P&gt;
&lt;P&gt;How many records does the view point to?&lt;/P&gt;</description>
      <pubDate>Mon, 07 Aug 2017 02:12:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-DBMS-tables-faster-from-SAS/m-p/385924#M92380</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-08-07T02:12:20Z</dc:date>
    </item>
    <item>
      <title>Re: update SAS tables Faster!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-DBMS-tables-faster-from-SAS/m-p/385963#M92392</link>
      <description>&lt;P&gt;You should show your code so we can try it.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Aug 2017 09:21:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-DBMS-tables-faster-from-SAS/m-p/385963#M92392</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-08-07T09:21:48Z</dc:date>
    </item>
    <item>
      <title>Re: update SAS tables Faster!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-DBMS-tables-faster-from-SAS/m-p/386176#M92461</link>
      <description>&lt;P&gt;Which database and version?&lt;/P&gt;&lt;P&gt;I tried this solution on Oracle and SQL server Databases&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Where are the view and hash table created?&lt;/P&gt;&lt;P&gt;view is created on the database engine like&amp;nbsp;&lt;/P&gt;&lt;P&gt;create view xx as select * from table_1 ; in Oracle&amp;nbsp;&lt;/P&gt;&lt;P&gt;then i read this view in sas using libname oracle ...&lt;/P&gt;&lt;P&gt;you can update in this view and your update will reflect on the physical tables&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How many records does the view point to?&lt;/P&gt;&lt;P&gt;i tried it on large table about 3 Milion&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2017 06:16:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-DBMS-tables-faster-from-SAS/m-p/386176#M92461</guid>
      <dc:creator>Amahareek</dc:creator>
      <dc:date>2017-08-08T06:16:06Z</dc:date>
    </item>
    <item>
      <title>Re: update SAS tables Faster!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-DBMS-tables-faster-from-SAS/m-p/386178#M92463</link>
      <description>&lt;P&gt;It has different techniques based on what you need to do&amp;nbsp;&lt;/P&gt;&lt;P&gt;suppose you want to update join from table_1 column party_name from table_2 column customer_name&amp;nbsp;&lt;/P&gt;&lt;P&gt;where party_number = customer_number&amp;nbsp;&lt;/P&gt;&lt;P&gt;and party_date_of_birth is missing&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First create view on table_1 say table_1_view on db say SQL server or Oracle&lt;/P&gt;&lt;P&gt;create view &lt;SPAN&gt;table_1_view&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;as&lt;/P&gt;&lt;P&gt;SELECT party_number, party_name&amp;nbsp;&lt;/P&gt;&lt;P&gt;From &amp;nbsp; &amp;nbsp; &amp;nbsp; Table_1&amp;nbsp;&lt;/P&gt;&lt;P&gt;where &amp;nbsp; &amp;nbsp; &amp;nbsp;party_date_of_birth is null;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in SAS&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc SQL;&lt;/P&gt;&lt;P&gt;create table work.table_1_view_update as&amp;nbsp;&lt;/P&gt;&lt;P&gt;SELECT party_number , customer_name as party_name /* this alias for the hash */&lt;/P&gt;&lt;P&gt;FROM &amp;lt;DB_libname&amp;gt;.table_1_view a inner join&amp;nbsp;&lt;SPAN&gt;&amp;lt;DB_libname&amp;gt;.table_2 b&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;on b.customer_number = a.party_number&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;;Quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;now work.table_1_view has the update we need&amp;nbsp;&lt;/P&gt;&lt;P&gt;let's use the hash to update&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data &lt;STRONG&gt;&amp;lt;DB_libname&amp;gt;.table_1_view&lt;/STRONG&gt;;&lt;BR /&gt;if _n_=1 then do;&lt;BR /&gt;declare hash ud(dataset:'&lt;SPAN&gt;work.table_1_view_update&lt;/SPAN&gt;');&lt;BR /&gt;ud.defineKey('party_number');&lt;BR /&gt;ud.defineData('party_name');&lt;BR /&gt;ud.defineDone();&lt;BR /&gt;end;&lt;BR /&gt;modify &lt;STRONG&gt;&amp;lt;DB_libname&amp;gt;.table_1_view&lt;/STRONG&gt;;&lt;BR /&gt;rcUpdate = ud.find();&lt;BR /&gt;if rcUpdate=0 then replace;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i hope this helps&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2017 06:30:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-DBMS-tables-faster-from-SAS/m-p/386178#M92463</guid>
      <dc:creator>Amahareek</dc:creator>
      <dc:date>2017-08-08T06:30:12Z</dc:date>
    </item>
    <item>
      <title>Re: update SAS tables Faster!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-DBMS-tables-faster-from-SAS/m-p/386181#M92464</link>
      <description>&lt;P&gt;&amp;lt;Erroneous reply removed&amp;gt; Thank you. This is an interesting idea. Will look at it more closely tomorrow.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2017 11:55:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-DBMS-tables-faster-from-SAS/m-p/386181#M92464</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-08-08T11:55:48Z</dc:date>
    </item>
    <item>
      <title>Re: update SAS tables Faster!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-DBMS-tables-faster-from-SAS/m-p/386296#M92490</link>
      <description>&lt;P&gt;Personally I never find it that useful to update a table in place. &amp;nbsp;SAS is not really designed to manage transactional databases.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How is this different than just creating an INDEX on the transaction table and using that instead of the HASH?&lt;/P&gt;
&lt;P&gt;Also what about creating an INDEX on the master table instead of the transactions?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does the HASH method run faster?&lt;/P&gt;
&lt;P&gt;What are the limitations? It would seem to me that the HASH would limit updates to number that could fit in memory. &amp;nbsp;That might not be much of a real issue. If you are applying more updates than you can loading into a HASH object then you are probably using the wrong method to maintain the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2017 15:14:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-DBMS-tables-faster-from-SAS/m-p/386296#M92490</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-08-08T15:14:55Z</dc:date>
    </item>
    <item>
      <title>Re: update SAS tables Faster!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-DBMS-tables-faster-from-SAS/m-p/386445#M92554</link>
      <description>&lt;P&gt;Ok I created a quick benchmark than anyone can run.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your method is indeed faster than a non-indexed update. That's quite a process to have combined the modify statment and a hash table on RDBMS data. Kudos!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below I test:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1-Table update in Oracle&lt;/P&gt;
&lt;P&gt;2- View&amp;nbsp;update in Oracle&lt;/P&gt;
&lt;P&gt;3-&amp;nbsp;View update with hash table in SAS&lt;/P&gt;
&lt;P&gt;4-&amp;nbsp;Table update in Oracle w/index&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The index wins hands down, but when that's not an option, the hash table saves a lot of time.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*0- Sample data;
data ORALIB.TESTBASE
     ORALIB.TESTUPDATE;
  do I=1 to 1e5;
    J=I*(ranuni(0) &amp;gt; 0.1); output ORALIB.TESTBASE;
    J=I;                   output ORALIB.TESTUPDATE;
  end;
run;
  

*Test 1 - Table update in Oracle - 60s; 
proc sql; 
  connect using ORALIB;
  execute by ORALIB(
    update TESTBASE
    set J = (select J from TESTUPDATE where TESTBASE.I=TESTUPDATE.I)
    where TESTBASE.J=0
  ); 
quit;


*Test 2 - View update in Oracle - 60s; 
proc sql; 
  connect using ORALIB;
  execute by ORALIB(
    create view TESTVIEW as 
    select I,J from TESTBASE 
    where TESTBASE.J=0
  ); 
  execute by ORALIB(
    update TESTVIEW
    set J = (select J from TESTUPDATE where TESTVIEW.I=TESTUPDATE.I)
  ); 
quit;


*Test 3 - View update with hash table in SAS - 18s; 
proc sql;
  create table UPD as 
  select u.* 
  from ORALIB.TESTVIEW   v
         inner join
       ORALIB.TESTUPDATE u
         on v.I=u.I;
quit;

data ORALIB.TESTVIEW;
  if _n_=1 then do;
    declare hash UPD(dataset:'UPD');
    UPD.defineKey('I');
    UPD.defineData('J');
    UPD.defineDone();
  end;
  modify ORALIB.TESTVIEW;
  RC = UPD.find();
  if RC=0 then replace;
run;


*Test 4 - Table update in Oracle w/index - 1s; 
proc sql; 
  connect using ORALIB;
  execute by ORALIB(
    create index I on TESTUPDATE(I)
  );
  execute by ORALIB(
    update TESTBASE
    set J = (select J from TESTUPDATE where TESTBASE.I=TESTUPDATE.I)
    where TESTBASE.J=0
  ); 
quit;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2017 23:04:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-DBMS-tables-faster-from-SAS/m-p/386445#M92554</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-08-08T23:04:24Z</dc:date>
    </item>
    <item>
      <title>Re: update SAS tables Faster!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-DBMS-tables-faster-from-SAS/m-p/386487#M92577</link>
      <description>&lt;P&gt;You should expand your subject line; it should read:&lt;/P&gt;
&lt;P&gt;Update DBMS tables faster from SAS&lt;/P&gt;
&lt;P&gt;as you are not updating native SAS tables.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2017 06:22:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-DBMS-tables-faster-from-SAS/m-p/386487#M92577</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-08-09T06:22:09Z</dc:date>
    </item>
    <item>
      <title>Re: update SAS tables Faster!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-DBMS-tables-faster-from-SAS/m-p/386498#M92584</link>
      <description>&lt;P&gt;thanks&amp;nbsp;Kurt&amp;nbsp;&lt;SPAN class="login-bold"&gt;i've already updated topic name&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2017 07:04:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-DBMS-tables-faster-from-SAS/m-p/386498#M92584</guid>
      <dc:creator>Amahareek</dc:creator>
      <dc:date>2017-08-09T07:04:21Z</dc:date>
    </item>
  </channel>
</rss>

