<?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: What is the efficient ways to Load SAS table into MS Sql Server in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-efficient-ways-to-Load-SAS-table-into-MS-Sql-Server/m-p/650525#M195066</link>
    <description>&lt;P&gt;Thanks Quentin, creating an empty table then use proc append, is it something like below?&lt;/P&gt;&lt;P&gt;I am going to try this method and I am curious why doing so will improve performance?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again for your advices.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;data spdslib.cars; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;set somelib.cars(obs=0); &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;PROC APPEND &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;base=spdslib.cars &lt;/SPAN&gt;&lt;SPAN&gt;data=somelib.cars; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 25 May 2020 20:47:05 GMT</pubDate>
    <dc:creator>LL5</dc:creator>
    <dc:date>2020-05-25T20:47:05Z</dc:date>
    <item>
      <title>What is the efficient ways to Load SAS table into MS Sql Server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-efficient-ways-to-Load-SAS-table-into-MS-Sql-Server/m-p/650514#M195060</link>
      <description>&lt;P&gt;Hi, I need to load several tables from SAS (on unix) to a database on MS SQL Server. The upload time is very long which takes more than 4 hours to load about 870 thousand rows. Some of my tables have more than 3 million rows which takes 18 hours.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two questions: 1) Why it takes so long to load data from SAS (on unix) to MS SQL server? More importantly 2) What would be the ways to improve the load time?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I realized bulkload is not available in unix and I tried compress = Yes in the data step but it seems to not work well either. I need to improve the processing time and appericated for any advices. Below are the codes and the logs.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;LIBNAME db ODBC UID=&amp;amp;sqluid PWD=&amp;amp;sqlpwd DSN=WH SCHEMA=Inv_info ; /* this is the database on SQL server*/&lt;/P&gt;&lt;P&gt;LIBNAME me '/Shared/Inv1/users/tom/monthly/'; /* my own user folder which contains all the tables to be loaded into SQL server*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA DB.wh_inv1;&lt;BR /&gt;SET ME.wh_inv1_test;&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;NOTE: Libref ME was successfully assigned as follows:&lt;BR /&gt;Engine: V9&lt;BR /&gt;Physical Name: /Shared/Inv1/users/tom/monthly&lt;BR /&gt;24 LIBNAME db ODBC UID=&amp;amp;sqluid PWD=&amp;amp;sqlpwd DSN=WH SCHEMA=Inv_info ;&lt;BR /&gt;NOTE: Libref DB was successfully assigned as follows:&lt;BR /&gt;Engine: ODBC&lt;BR /&gt;Physical Name: WH&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;NOTE: SAS variable labels, formats, and lengths are not written to DBMS tables.&lt;BR /&gt;NOTE: There were 871607 observations read from the data set ME.wh_inv1_test.&lt;BR /&gt;NOTE: The data set DB.wh_inv1 has 871607 observations and 5 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 4:25:42.61&lt;BR /&gt;cpu time 2:05.47&lt;/P&gt;</description>
      <pubDate>Mon, 25 May 2020 19:44:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-efficient-ways-to-Load-SAS-table-into-MS-Sql-Server/m-p/650514#M195060</guid>
      <dc:creator>LL5</dc:creator>
      <dc:date>2020-05-25T19:44:12Z</dc:date>
    </item>
    <item>
      <title>Re: What is the efficient ways to Load SAS table into MS Sql Server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-efficient-ways-to-Load-SAS-table-into-MS-Sql-Server/m-p/650516#M195061</link>
      <description>&lt;P&gt;From UNIX I thought the SQLSRV engine was the standard to use.&amp;nbsp; It could be faster than the generic ODBC engine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also could could play with the INSERTBUFF option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's possible that it's faster to insert records into an existing table.&amp;nbsp; I usually create a table with 0 records, then use PROC APPEND to add to it.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also consider the networking involved.&amp;nbsp; That is, if you database server is far from the SAS server, you can spend a lot of time just passing data over the wire.&lt;/P&gt;</description>
      <pubDate>Mon, 25 May 2020 19:54:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-efficient-ways-to-Load-SAS-table-into-MS-Sql-Server/m-p/650516#M195061</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2020-05-25T19:54:00Z</dc:date>
    </item>
    <item>
      <title>Re: What is the efficient ways to Load SAS table into MS Sql Server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-efficient-ways-to-Load-SAS-table-into-MS-Sql-Server/m-p/650519#M195062</link>
      <description>&lt;P&gt;Try adding this to your ODBC LIBNAME statement: insertbuff = 10000&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this helps improve loading performance, then try higher or lower numbers to get the optimum value.&lt;/P&gt;</description>
      <pubDate>Mon, 25 May 2020 20:00:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-efficient-ways-to-Load-SAS-table-into-MS-Sql-Server/m-p/650519#M195062</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2020-05-25T20:00:27Z</dc:date>
    </item>
    <item>
      <title>Re: What is the efficient ways to Load SAS table into MS Sql Server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-efficient-ways-to-Load-SAS-table-into-MS-Sql-Server/m-p/650525#M195066</link>
      <description>&lt;P&gt;Thanks Quentin, creating an empty table then use proc append, is it something like below?&lt;/P&gt;&lt;P&gt;I am going to try this method and I am curious why doing so will improve performance?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again for your advices.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;data spdslib.cars; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;set somelib.cars(obs=0); &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;PROC APPEND &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;base=spdslib.cars &lt;/SPAN&gt;&lt;SPAN&gt;data=somelib.cars; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 25 May 2020 20:47:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-efficient-ways-to-Load-SAS-table-into-MS-Sql-Server/m-p/650525#M195066</guid>
      <dc:creator>LL5</dc:creator>
      <dc:date>2020-05-25T20:47:05Z</dc:date>
    </item>
    <item>
      <title>Re: What is the efficient ways to Load SAS table into MS Sql Server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-efficient-ways-to-Load-SAS-table-into-MS-Sql-Server/m-p/650528#M195069</link>
      <description>&lt;P&gt;Thanks SASKiwi, I am trying this method now.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did some researches and learned that by default SAS is inserting 1 row at a time into a third party relational database, by adding the inserbuff option will improve ODBC libraries dramatically.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wonder how does the number for insertbuff (i.e 10000 vs any higher or lower number) matter? Does higher number means faster and vice versa?&lt;/P&gt;</description>
      <pubDate>Mon, 25 May 2020 21:03:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-efficient-ways-to-Load-SAS-table-into-MS-Sql-Server/m-p/650528#M195069</guid>
      <dc:creator>LL5</dc:creator>
      <dc:date>2020-05-25T21:03:29Z</dc:date>
    </item>
    <item>
      <title>Re: What is the efficient ways to Load SAS table into MS Sql Server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-efficient-ways-to-Load-SAS-table-into-MS-Sql-Server/m-p/650529#M195070</link>
      <description>&lt;P&gt;Yes, that's what I often do.&amp;nbsp; I can't promise it will be faster.&amp;nbsp; &amp;nbsp;I do more reading from SQL server than writing to it.&amp;nbsp; But I thought SAS might have some better bulk loading options when you append to an existing table.&amp;nbsp; &amp;nbsp;Definitely play with insertbuff as well, e.g.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data spdslib.cars;
  set somelib.cars(obs=0);
run;
 
PROC APPEND base=spdslib.cars (insertbuff=1000) data=somelib.cars;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you really want to speed it up, ideally you'll have a DBA who wants to work with you and can look at what's happening on the database side, and also look at network traffic.&amp;nbsp; I've had some luck in finding DBA's who want to do that sort of investigation for a me as a SAS user, but it's rare. : )&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 May 2020 21:04:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-efficient-ways-to-Load-SAS-table-into-MS-Sql-Server/m-p/650529#M195070</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2020-05-25T21:04:25Z</dc:date>
    </item>
    <item>
      <title>Re: What is the efficient ways to Load SAS table into MS Sql Server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-efficient-ways-to-Load-SAS-table-into-MS-Sql-Server/m-p/650530#M195071</link>
      <description>&lt;P&gt;You really have to play with insertbuff to try to find an optimal setting.&amp;nbsp; My understanding is there are trade-offs in memory usage, etc.&amp;nbsp; So it's not always the case that the biggest insertbuff is optimal.&amp;nbsp; But definitely insertbuff=1 is slow.&amp;nbsp; I think some drivers might allow insertbuff=0 for SAS to try to guess at a good value.&lt;/P&gt;</description>
      <pubDate>Mon, 25 May 2020 21:06:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-efficient-ways-to-Load-SAS-table-into-MS-Sql-Server/m-p/650530#M195071</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2020-05-25T21:06:57Z</dc:date>
    </item>
    <item>
      <title>Re: What is the efficient ways to Load SAS table into MS Sql Server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-efficient-ways-to-Load-SAS-table-into-MS-Sql-Server/m-p/650535#M195074</link>
      <description>&lt;P&gt;Thanks Quentin, that sounds great. I tried the insertbuff=10000 and amazingly the load time improved to 1 minutes from 4 hours.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 May 2020 21:23:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-efficient-ways-to-Load-SAS-table-into-MS-Sql-Server/m-p/650535#M195074</guid>
      <dc:creator>LL5</dc:creator>
      <dc:date>2020-05-25T21:23:17Z</dc:date>
    </item>
    <item>
      <title>Re: What is the efficient ways to Load SAS table into MS Sql Server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-efficient-ways-to-Load-SAS-table-into-MS-Sql-Server/m-p/650536#M195075</link>
      <description>&lt;P&gt;Thanks. It worked! Sorry that I have one more question which relates to create an empty table and append row. Previously I had syntax error shown as below saying the ODBC table already exist, but in fact, that is a table never exist in the DB on Sql Server. I fixed this by deleting the table and it worked, but I don't understand why it says the table already exist (which is not true) and why do we need to delete a table before loading that table into a db on SQL Server?&lt;/P&gt;&lt;P&gt;Thanks again for your advices.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: The ODBC table INVENTORY2 has been opened for OUTPUT. This table already exists, or there is a name conflict with an existing&lt;BR /&gt;object. This table will not be replaced. This engine does not support the REPLACE option.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.05 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;/P&gt;</description>
      <pubDate>Mon, 25 May 2020 21:28:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-efficient-ways-to-Load-SAS-table-into-MS-Sql-Server/m-p/650536#M195075</guid>
      <dc:creator>LL5</dc:creator>
      <dc:date>2020-05-25T21:28:12Z</dc:date>
    </item>
    <item>
      <title>Re: What is the efficient ways to Load SAS table into MS Sql Server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-efficient-ways-to-Load-SAS-table-into-MS-Sql-Server/m-p/650537#M195076</link>
      <description>&lt;P&gt;From 4 hours to 1 minute is a nice improvement! : )&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In SAS, we are used to over-writing datasets, so:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new;
  set old;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will happily overwrite work.new without mentioning anything.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Databases don't do a lot of table creation and re-creation.&amp;nbsp; They're generally about reading and writing data to existing tables.&amp;nbsp; If a table exists, and you try to create a new table with the same name, they don't like it.&amp;nbsp; I think it's a defense against accidentally losing an entire table of data.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you use:&lt;/P&gt;
&lt;PRE&gt;data sql.new;
  set old;
run;&lt;/PRE&gt;
&lt;P&gt;And the SQL libref points to a sql server database that already has a table named NEW, the code will error.&amp;nbsp; It will not delete the table for you automatically.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can delete the table yourself.&amp;nbsp; Generally I find when I want to delete a SQL server table from SAS, it's fastest to use explicit pass-through to execute the drop table statement, e.g.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  connect using sql;  *libref SQL points to sql server;
  execute by sql 
  (
   drop table new ;
  );
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can also&amp;nbsp; use the delete command to empty all records from a table (while leaving the empty table in place), which is useful for testing load times, etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  connect using sql;
  execute by sql
  (
   delete from foo;
  );
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 May 2020 21:53:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-efficient-ways-to-Load-SAS-table-into-MS-Sql-Server/m-p/650537#M195076</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2020-05-25T21:53:48Z</dc:date>
    </item>
    <item>
      <title>Re: What is the efficient ways to Load SAS table into MS Sql Server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-efficient-ways-to-Load-SAS-table-into-MS-Sql-Server/m-p/650543#M195077</link>
      <description>&lt;P&gt;Ah I see. Thanks Quentin for all these useful information. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 May 2020 22:32:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-efficient-ways-to-Load-SAS-table-into-MS-Sql-Server/m-p/650543#M195077</guid>
      <dc:creator>LL5</dc:creator>
      <dc:date>2020-05-25T22:32:59Z</dc:date>
    </item>
    <item>
      <title>Re: What is the efficient ways to Load SAS table into MS Sql Server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-efficient-ways-to-Load-SAS-table-into-MS-Sql-Server/m-p/650681#M195141</link>
      <description>proc sql;&lt;BR /&gt;create table spdslib.cars  like  somelib.cars ;&lt;BR /&gt;quit;</description>
      <pubDate>Tue, 26 May 2020 11:24:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-efficient-ways-to-Load-SAS-table-into-MS-Sql-Server/m-p/650681#M195141</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-05-26T11:24:19Z</dc:date>
    </item>
    <item>
      <title>Re: What is the efficient ways to Load SAS table into MS Sql Server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-efficient-ways-to-Load-SAS-table-into-MS-Sql-Server/m-p/650740#M195163</link>
      <description>&lt;P&gt;Thanks Ksharp, I wonder why this approach could reduce the load time? It is like create a table from an existing table by copying the existing table's column, and the new table will be populated with the records from the existing table?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 May 2020 13:31:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-efficient-ways-to-Load-SAS-table-into-MS-Sql-Server/m-p/650740#M195163</guid>
      <dc:creator>LL5</dc:creator>
      <dc:date>2020-05-26T13:31:51Z</dc:date>
    </item>
    <item>
      <title>Re: What is the efficient ways to Load SAS table into MS Sql Server</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-efficient-ways-to-Load-SAS-table-into-MS-Sql-Server/m-p/651038#M195277</link>
      <description>I don't know. But  insertbuff=10000  definitely will enhance efficient .</description>
      <pubDate>Wed, 27 May 2020 11:04:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-efficient-ways-to-Load-SAS-table-into-MS-Sql-Server/m-p/651038#M195277</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-05-27T11:04:47Z</dc:date>
    </item>
  </channel>
</rss>

