<?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: SAS: how to make it write proper SQL that do not degrade performance 10000% or more against MS S in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/593738#M170459</link>
    <description>&lt;P&gt;I still see a high amount of MS SQL wait types of ASYNC_NETWORK_IO (SAS reads data slower than SQL sends it), it would be great to find a way to reduce this wait type, I have tried mulitple drivers, hints, options, libname tweaks etc without success. It primarily happens when SAS runs data "single threaded" instead of parallel processing, primarily when pulling back fields without a complex where/group by clause (that triggers the code to run on the server then pull back the summary). I would love this wait type to go away, it only occurs when SAS communicates to sql.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.sqlshack.com/reducing-sql-server-async_network_io-wait-type/" target="_blank"&gt;https://www.sqlshack.com/reducing-sql-server-async_network_io-wait-type/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The server is enterprise with 768GB of ram and 24 cores (xeon), it can read/write at 2000MBs+. Often users are pulling data down to their slower local drives into sas, which it can help if a "summary is ran against sql" instead of reproducing tables locally.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A few tips that I have passed on to others:&lt;/P&gt;&lt;P&gt;a. if your joining a table that exists in SAS to SQL, that table doesnt exist in SQL so SAS will "select the columns needed and pull them back to sas then join", so they could add the table to sql if needed (and index it) or index their table in sas&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;b. remove "SAS" code that doesnt exist in sql (macro variables, certain functions etc)&lt;/P&gt;</description>
    <pubDate>Thu, 03 Oct 2019 14:29:10 GMT</pubDate>
    <dc:creator>JroeJroe</dc:creator>
    <dc:date>2019-10-03T14:29:10Z</dc:date>
    <item>
      <title>SAS: how to make it write proper SQL that do not degrade performance 10000% or more against MS SQL?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/544093#M150448</link>
      <description>&lt;P&gt;As a MS SQL DB admin I often find SAS code running inefficiently on the server which will generate "network I/O sync" wait times (degraded performance), run serial/single threaded (not parallel) and the queries from SAS are rewritten poorly in SQL or inefficiently. This occurs primarily when any custom SAS logic is used (macros) and the same behavior occurs with PROCSQL and data steps. This is a simple example.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example a PROC SQL statement:&lt;/P&gt;&lt;P&gt;SELECT&lt;/P&gt;&lt;P&gt;&amp;nbsp; A,B , SUM(PAID) AS PAID&lt;/P&gt;&lt;P&gt;FROM X&lt;/P&gt;&lt;P&gt;WHERE A between 2000 and 3000&lt;/P&gt;&lt;P&gt;GROUP BY&lt;/P&gt;&lt;P&gt;A,B&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What it should do is rewrite a similar query in SQL. However when you look at SQL this is how the thread will look like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SELECT "A", "B",&amp;nbsp; "PAID"&lt;BR /&gt;FROM X&lt;BR /&gt;WHERE ( ( "A" between "2000" and "3000"))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- it is not performing a GROUP statement. So it ends up pulling ALL records serial/single threaded over the network (300mil rows) to the person's SAS workspace/PC THEN it performs the group by statement in house. The table is columnstore indexed and can be summarized in SQL in 5 seconds vs hours in SAS (since SAS wants to recreate EACH ROW on a local pc, over a network, single threaded...)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BULK INSERTS perform even worse with even more bizarre code observed in SQL .&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;LIBNAME TEST ODBC NOPROMPT =&lt;BR /&gt;"Driver=SQL Server Native Client 11.0;&lt;BR /&gt;Server=myserver;&lt;BR /&gt;Database=myDB;&lt;BR /&gt;dbsliceparm=all;&lt;BR /&gt;threads=yes CPUCOUNT=8;&lt;BR /&gt;READBUFF=32767;&lt;BR /&gt;DBOMMIT=32767;&lt;BR /&gt;INSERTBUFF=32767;&lt;BR /&gt;ROWSET_SIZE=32767;&lt;BR /&gt;Trusted_Connection=Yes;"&lt;BR /&gt;Schema = TEST ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2019 19:34:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/544093#M150448</guid>
      <dc:creator>JroeJroe</dc:creator>
      <dc:date>2019-03-18T19:34:49Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: how to make it write proper SQL that do not degrade performance 10000% or more against MS S</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/544101#M150450</link>
      <description>&lt;P&gt;You can use Explicit passthrough if you want to write native MS SQL to run against the Database .&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2019 20:32:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/544101#M150450</guid>
      <dc:creator>34reqrwe</dc:creator>
      <dc:date>2019-03-18T20:32:32Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: how to make it write proper SQL that do not degrade performance 10000% or more against MS S</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/544102#M150451</link>
      <description>&lt;P&gt;do you have an example? I had googled that for a few hours last week and didn't get far. Also I'm not sure why SAS sometimes writes "good sql" and sometimes it writes bizarro slow sql that will take 10000%+ longer to process. Appreciate it!&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2019 20:33:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/544102#M150451</guid>
      <dc:creator>JroeJroe</dc:creator>
      <dc:date>2019-03-18T20:33:32Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: how to make it write proper SQL that do not degrade performance 10000% or more against MS S</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/544104#M150452</link>
      <description>&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/acreldb/65247/HTML/default/viewer.htm#p09s44hpea09stn1puyx1l5vcwwt.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/acreldb/65247/HTML/default/viewer.htm#p09s44hpea09stn1puyx1l5vcwwt.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2019 20:52:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/544104#M150452</guid>
      <dc:creator>34reqrwe</dc:creator>
      <dc:date>2019-03-18T20:52:25Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: how to make it write proper SQL that do not degrade performance 10000% or more against MS S</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/544105#M150453</link>
      <description>so there is no way for proc sql and data steps to write normal/expected standard sql queries in a standard fashion other than passthrough? (like libname hints etc)?&lt;BR /&gt;&lt;BR /&gt;its random and when SAS does it its often 1000x slower.</description>
      <pubDate>Mon, 18 Mar 2019 20:53:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/544105#M150453</guid>
      <dc:creator>JroeJroe</dc:creator>
      <dc:date>2019-03-18T20:53:53Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: how to make it write proper SQL that do not degrade performance 10000% or more against MS S</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/544106#M150454</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/266959"&gt;@JroeJroe&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;As a MS SQL DB admin I often find SAS code running inefficiently on the server which will generate "network I/O sync" wait times (degraded performance), run serial/single threaded (not parallel) and the queries from SAS are rewritten poorly in SQL or inefficiently. &lt;FONT color="#FF6600"&gt;&lt;STRONG&gt;&lt;FONT color="#000000"&gt;This occurs primarily when any custom SAS logic is used&lt;/FONT&gt; (macros)&lt;/STRONG&gt; &lt;/FONT&gt;and the same behavior occurs with PROCSQL and data steps. This is a simple example.&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is hardly possible (red marked text), because the macro-PRE-processor finished his job long before any code is send to MS SQL DB. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/266959"&gt;@JroeJroe&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;LIBNAME TEST &lt;FONT color="#FF6600"&gt;&lt;STRONG&gt;ODBC&lt;/STRONG&gt; &lt;/FONT&gt;NOPROMPT =&lt;BR /&gt;"Driver=SQL Server Native Client 11.0;&lt;BR /&gt;Server=myserver;&lt;BR /&gt;Database=myDB;&lt;BR /&gt;dbsliceparm=all;&lt;BR /&gt;threads=yes CPUCOUNT=8;&lt;BR /&gt;READBUFF=32767;&lt;BR /&gt;DBOMMIT=32767;&lt;BR /&gt;INSERTBUFF=32767;&lt;BR /&gt;ROWSET_SIZE=32767;&lt;BR /&gt;Trusted_Connection=Yes;"&lt;BR /&gt;Schema = TEST ;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The problems could be a consequence of using an odbc connection instead of a native mssql library. Do you have Access to MSSQL licenced?&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2019 20:53:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/544106#M150454</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-03-18T20:53:56Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: how to make it write proper SQL that do not degrade performance 10000% or more against MS S</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/544108#M150455</link>
      <description>&lt;P&gt;1. If your query really is that simple, SAS should pass the GROUP BY clause to the database.&lt;/P&gt;
&lt;P&gt;It is puzzling that is does not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Learn how to use pass-through. It is really simple to implement and allows you full control of the code.&lt;/P&gt;
&lt;P&gt;I have a hard time believing you "&lt;SPAN&gt;googled that for a few hours last week and didn't get far"&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname EXTDATA &amp;lt;connections parameters&amp;gt;;
proc sql;
  connect using EXTDATA;
  create table T as select * &amp;lt;SAS SQL here&amp;gt; from connection to EXTDATA 
     ( &amp;lt;native SQL here&amp;gt; )
  &amp;lt; more SAS SQL here like order by &amp;gt;
  ;  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Anything between the parentheses is native SQL, anything outside is SAS SQL.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;3. The libname statement you are showing is SAS code, to point to your ODBC source. Nothing to do with SQL.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2019 21:03:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/544108#M150455</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-03-18T21:03:41Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: how to make it write proper SQL that do not degrade performance 10000% or more against MS S</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/544110#M150457</link>
      <description>&lt;P&gt;Back up a bit, trying to keep things simple for support and not pick a fight with folks. I am looking at simple code statements from a MS SQL DBA perspective that rarely uses sas (sas , lets say we have 10000 different projects, in no way can I have 500 people change thousands of lines of code to pass through sql) , but I will test it since I think its a super handy tool for when "Speed is important", in those cases we simply replace SAS with SQL and process stuff 1000x faster anyway. What I would like to see is SAS handle simple queries in a simple manner in PROC SQL or DATA steps when communicating with MS SQL which is why I'm hoping to find out what is causing the odd processing methodologies observed in SSMS from SAS code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Andrea Could you help provide an example of:&lt;/P&gt;&lt;P&gt;"&lt;SPAN&gt;The problems could be a consequence of using an odbc connection instead of a native mssql library. Do you have Access to MSSQL licenced?"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Yes I have both SQL Enterprise and SQL Standard. Both handle some (mostly all ) SAS code in the same bizarre manner. However sometimes it runs good sql/normal and it is fine. I'm ok with switching how the libname is configured thanks!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2019 21:07:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/544110#M150457</guid>
      <dc:creator>JroeJroe</dc:creator>
      <dc:date>2019-03-18T21:07:40Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: how to make it write proper SQL that do not degrade performance 10000% or more against MS S</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/544113#M150460</link>
      <description>&lt;P&gt;You need to have SAS Access to MSSQL licenced, you can check with proc setinit;run;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2019 21:12:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/544113#M150460</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-03-18T21:12:46Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: how to make it write proper SQL that do not degrade performance 10000% or more against MS S</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/544114#M150461</link>
      <description>&lt;P&gt;thanks! I dont see MSSQL being specified, do you have an example of what it looks like? There are a ton of other items. Also would you have an example libname then i'd have to use after?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;---Base SAS Software&lt;BR /&gt;30NOV2019 (CPU A)&lt;BR /&gt;---SAS/STAT&lt;BR /&gt;30NOV2019 (CPU A)&lt;BR /&gt;---SAS/GRAPH&lt;BR /&gt;30NOV2019 (CPU A)&lt;BR /&gt;---SAS/ETS&lt;BR /&gt;30NOV2019 (CPU A)&lt;BR /&gt;---SAS/FSP&lt;BR /&gt;30NOV2019 (CPU A)&lt;BR /&gt;---SAS/OR&lt;BR /&gt;30NOV2019 (CPU A)&lt;BR /&gt;---SAS/AF&lt;BR /&gt;30NOV2019 (CPU A)&lt;BR /&gt;---SAS/IML&lt;BR /&gt;30NOV2019 (CPU A)&lt;BR /&gt;---SAS/QC&lt;BR /&gt;30NOV2019 (CPU A)&lt;BR /&gt;---SAS/CONNECT&lt;BR /&gt;30NOV2019 (CPU A)&lt;BR /&gt;---SAS/EIS&lt;BR /&gt;30NOV2019 (CPU A)&lt;BR /&gt;---SAS/GIS&lt;BR /&gt;30NOV2019 (CPU A)&lt;BR /&gt;---SAS Enterprise Miner&lt;BR /&gt;30NOV2018 (CPU A)&lt;BR /&gt;---MDDB Server common products&lt;BR /&gt;30NOV2019 (CPU A)&lt;BR /&gt;---SAS/Secure 168-bit&lt;BR /&gt;30NOV2019 (CPU A)&lt;BR /&gt;---SAS/Secure Windows&lt;BR /&gt;30NOV2019 (CPU A)&lt;BR /&gt;---SAS Text Miner&lt;BR /&gt;30NOV2018 (CPU A)&lt;BR /&gt;---SAS Enterprise Guide&lt;BR /&gt;30NOV2019 (CPU A)&lt;BR /&gt;---OR OPT&lt;BR /&gt;30NOV2019 (CPU A)&lt;BR /&gt;---OR PRS&lt;BR /&gt;30NOV2019 (CPU A)&lt;BR /&gt;---OR IVS&lt;BR /&gt;30NOV2019 (CPU A)&lt;BR /&gt;---OR LSO&lt;BR /&gt;30NOV2019 (CPU A)&lt;BR /&gt;---SAS/ACCESS Interface to PC Files&lt;BR /&gt;30NOV2019 (CPU A)&lt;BR /&gt;---SAS/ACCESS Interface to ODBC&lt;BR /&gt;30NOV2019 (CPU A)&lt;BR /&gt;---SAS/ACCESS Interface to OLE DB&lt;BR /&gt;30NOV2019 (CPU A)&lt;BR /&gt;---SAS Enterprise Miner for Desktop&lt;BR /&gt;30NOV2018 (CPU A)&lt;BR /&gt;---SAS/IML Studio&lt;BR /&gt;30NOV2019 (CPU A)&lt;BR /&gt;---SAS Workspace Server for Local Access&lt;BR /&gt;30NOV2019 (CPU A)&lt;BR /&gt;---High Performance Suite&lt;BR /&gt;30NOV2019 (CPU A)&lt;BR /&gt;---SAS Add-in for Microsoft Excel&lt;BR /&gt;30NOV2018 (CPU A)&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2019 21:15:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/544114#M150461</guid>
      <dc:creator>JroeJroe</dc:creator>
      <dc:date>2019-03-18T21:15:13Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: how to make it write proper SQL that do not degrade performance 10000% or more against MS S</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/544118#M150464</link>
      <description>&lt;P&gt;1. Code translation&lt;/P&gt;
&lt;P&gt;If this helps, you can see the statement that SAS sends to the database by using options &lt;A href="https://documentation.sas.com/?docsetId=engfedsrv&amp;amp;docsetTarget=n167fxh8cc9h2an198cln7b46vb9.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;SASTRACE&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;SAS usually does a good job of passing most clauses to the database.&lt;/P&gt;
&lt;P&gt;ODBC is generic, so a native engine is better in that respect as highlighted by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Pass-thru&lt;/P&gt;
&lt;P&gt;As soon as SAS-specific function are used, the process cannot be passed to the database.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So something like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;SELECT
  A, put(B,z2.) as B, SUM(PAID) AS PAID
FROM X
WHERE A between 2000 and 3000
GROUP BY 1,2&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will run entirely in SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. Performance&lt;/P&gt;
&lt;P&gt;Which is faster varies. For example, since SQL databases do not maintain sorted tables, full table joins are usually very much faster in SAS on similar hardware.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2019 22:36:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/544118#M150464</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-03-18T22:36:51Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: how to make it write proper SQL that do not degrade performance 10000% or more against MS S</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/548056#M151938</link>
      <description>&lt;P&gt;I haven't been able to get SAS to consistently write standard code ( I know macro variables and other functions can lead to abnormal code which I often advise folks not to use when talking to SQL).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is what I did to get bulkload to use tablock (simplified logging) which should stop SAS from creating 2TB files.&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;LIBNAME SAS ODBC NOPROMPT = 
"Driver=SQL Server Native Client 11.0;
Server=MYSERVER; 
BULKLOAD=YES;
BL_OPTIONS=TABLOCK;
READBUFF=100000;
DBOMMIT=300000;
INSERTBUFF=32767;
ROWSET_SIZE=32767;
UPDATE_LOCK_TYPE=TABLE;
Trusted_Connection=Yes;
Database=MYDATABASE;
dbsliceparm=all;
threads=yes;
CPUCOUNT=12;
" 
Schema = dbo;&lt;BR /&gt;
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data 
	SAS.MYNEWTABLE (BULKLOAD=YES BL_RECOVERABLE=NO DBCOMMIT=300000 INSERTBUFF=32767 UPDATE_LOCK_TYPE=TABLE READ_LOCK_TYPE=TABLE); 

set MYSASDATA;
run;&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, 02 Apr 2019 22:05:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/548056#M151938</guid>
      <dc:creator>jroe</dc:creator>
      <dc:date>2019-04-02T22:05:45Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: how to make it write proper SQL that do not degrade performance 10000% or more against MS S</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/548067#M151944</link>
      <description>&lt;P&gt;Using ODBC is unlikely to support any smart parameters or specific settings.&lt;/P&gt;
&lt;P&gt;It is a dumb pipe that's very useful for generic connectivity, but generally unsuited for large volumes or when more control is required.&lt;/P&gt;
&lt;P&gt;I see that you also have SAS/ACCESS to OLEDB. You can try this interface though the limitations are possibly similar.&lt;/P&gt;
&lt;P&gt;Other options:&lt;/P&gt;
&lt;P&gt;- Check that the native SAS/ACCESS interface does what you need, test it and licence it&lt;/P&gt;
&lt;P&gt;- Use flat files&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2019 22:04:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/548067#M151944</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-04-02T22:04:37Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: how to make it write proper SQL that do not degrade performance 10000% or more against MS S</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/548068#M151945</link>
      <description>Do you have a sample OLEDB connection libname statement to MS SQL server? I tried the guide but wasn't able to get it to work. Thanks!</description>
      <pubDate>Tue, 02 Apr 2019 22:06:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/548068#M151945</guid>
      <dc:creator>jroe</dc:creator>
      <dc:date>2019-04-02T22:06:40Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: how to make it write proper SQL that do not degrade performance 10000% or more against MS S</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/548069#M151946</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt; I haven't been able to get SAS to consistently write standard code ( I know macro variables and other functions can lead to abnormal code which I often advise folks not to use when talking to SQL).&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is standard code?&lt;/P&gt;
&lt;P&gt;SAS does not write code (except for the implicit pass-through optimisations) and macros do no write code either.&lt;/P&gt;
&lt;P&gt;Macros don't write abnormal code. This sentence has no meaning as stated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I see that you found a way to do what you needed:&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; SAS&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;MYNEWTABLE &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;BULKLOAD&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;YES BL_RECOVERABLE&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;NO DBCOMMIT&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;300000&lt;/SPAN&gt; INSERTBUFF&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;32767&lt;/SPAN&gt; UPDATE_LOCK_TYPE&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token statement"&gt;TABLE&lt;/SPAN&gt; READ_LOCK_TYPE&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token statement"&gt;TABLE&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; 
&lt;SPAN class="token keyword"&gt;  set&lt;/SPAN&gt; MYSASDATA&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Well done for finding, testing and implementing these options.&lt;/P&gt;
&lt;P&gt;What is the issue now? Is it that you'd like these option to be part of the default libname setting?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that proc copy or proc append are faster than a data step for simply copying tables.&lt;/P&gt;
&lt;P&gt;Also note that the table creation can be accelerated by setting larger values for options BUFNO and BUFSIZE, and possibly by using Windows's SGIO, if disk I/O is the culprit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2019 22:28:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/548069#M151946</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-04-02T22:28:52Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: how to make it write proper SQL that do not degrade performance 10000% or more against MS S</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/548074#M151948</link>
      <description>&lt;P&gt;&lt;SPAN&gt;&lt;EM&gt;&amp;gt; Do you have a sample OLEDB connection libname statement to MS SQL server?&lt;/EM&gt; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Sorry I don't&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2019 22:50:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/548074#M151948</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-04-02T22:50:51Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: how to make it write proper SQL that do not degrade performance 10000% or more against MS S</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/548088#M151957</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;SELECT

  A,B , SUM(PAID) AS PAID

FROM X

WHERE A between 2000 and 3000

GROUP BY

A,B&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;As others have said, use explicit pass through (esp. if you don't use SAS much).&amp;nbsp; With explicit pass through, SAS is just a client to SQL Server, analogous to Powershell, .Net, SSMS, Toad, etc.&amp;nbsp; IOW, it's just passing SQL to your RDBMS (SQL Server).&amp;nbsp; You could submit the same query via Powershell (Invoke-Sqlcmd) and return the data to the console (say to pipe to ConvertT-Csv)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As to your query, what I think is happening is, SUM() is both a SAS and SQL Server function.&amp;nbsp; If a SAS &lt;U&gt;implicit&lt;/U&gt; pass through query contains a SAS function, formats, etc, a more generic query is sent to the RDBMS, then SAS does the aggregation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would write your query as explicit pass through as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* set desired SAS options ;
options sastrace=',,,d' sastraceloc=saslog nostsuffix;
options dbidirectexec;
options msglevel=I;
options fullstimer;

* allocate SQL Server libraries ;
%libname_sqlsvr(libref=FOO,server=MY_SS_SERVER,port=,database=my_database,schema=dbo)

proc sql;
   connect using foo;
   create table blah as
   select *
   from connection to foo (
SELECT A
      ,B
      ,SUM(PAID) AS PAID
  FROM X
 WHERE A between 2000 and 3000
GROUP BY
       A
      ,B
   );
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Debug your query in SQL Server Management Studio.&amp;nbsp; The explicit pass through should then have similar performance as via SSMS, barring the network traffic to send the &lt;U&gt;aggregated&lt;/U&gt; data back to SAS to create the data set.&amp;nbsp; And hopefully that aggregation is "small".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I see you have Access to ODBC and Access to OLEDB.&amp;nbsp; We use ODBC; if you want to use it (or at least try it) as well, perhaps this may help:&amp;nbsp;&amp;nbsp;&lt;A href="https://github.com/scottbass/SAS/blob/master/Macro/libname_sqlsvr.sas" target="_blank"&gt;https://github.com/scottbass/SAS/blob/master/Macro/libname_sqlsvr.sas&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That macro may get you started, otherwise hit the doc for either ODBC or OLEDB.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Apr 2019 01:18:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/548088#M151957</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-04-03T01:18:31Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: how to make it write proper SQL that do not degrade performance 10000% or more against MS S</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/548234#M152009</link>
      <description>Thanks for the feeback! Is your example pass through sql though or just "as clean/normal sql as possible"?&lt;BR /&gt;&lt;BR /&gt;I agree when I coach folks to not use variables or sas specific stuff their code runs better (it usually rewrites the query better once it hits ms sql"). Thanks!</description>
      <pubDate>Wed, 03 Apr 2019 14:52:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/548234#M152009</guid>
      <dc:creator>jroe</dc:creator>
      <dc:date>2019-04-03T14:52:26Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: how to make it write proper SQL that do not degrade performance 10000% or more against MS S</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/548260#M152013</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/66889"&gt;@jroe&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is proper SQL. Everything you write in the &lt;STRONG&gt;connection to xxx ( &amp;lt;sql-code&amp;gt; );&lt;/STRONG&gt; construct is just passed to SQL. So a query copied from Microsoft SQL Server manager will work, as shown in the following example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;LIBNAME xmanbmf ODBC  IGNORE_READ_ONLY_COLUMNS=YES  DATAsrc=EXT_Manuel_BMF  SCHEMA=dbo ;
proc sql;
	connect using xmanbmf as myconnect;
	create table work.blah as
		select *
			from connection to myconnect (

SELECT TOP (1000) [SysID]
,[jobstatus]
,[jobstatus_tekst]
FROM [DWH_MAN_BMF].[dbo].[sd_jobstatus]

			);
	disconnect from myconnect;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You are not limited to queries, where you use the result as input to SAS. Any SQL command can be passed using the&amp;nbsp;&lt;STRONG&gt;execute ( &amp;lt;sql-code&amp;gt; ) by xxx; &lt;/STRONG&gt;construct as shown:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;LIBNAME xmanbmf ODBC  IGNORE_READ_ONLY_COLUMNS=YES  DATAsrc=EXT_Manuel_BMF  SCHEMA=dbo ;
proc sql;
	connect using xmanbmf as myconnect;
	execute (

CREATE TABLE [DWH_MAN_BMF].[dbo].[test2_jobstatus](
	[SysID] [int] IDENTITY(1,1) NOT NULL,
	[jobstatus] [char](1) NULL,
	[jobstatus_tekst] [varchar](60) NULL
)

	) by myconnect;
	disconnect from myconnect;
quit;&lt;/CODE&gt;&lt;/PRE&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>Wed, 03 Apr 2019 15:57:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/548260#M152013</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-04-03T15:57:40Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: how to make it write proper SQL that do not degrade performance 10000% or more against MS S</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/548264#M152015</link>
      <description>&lt;P&gt;I am not sure I understand your point.&amp;nbsp; In SQL code you just describe what output set you want to create. It is up the the implementer (the database that is accepting the SQL) to do any needed optimizations.&amp;nbsp; It can be very tricky.&amp;nbsp; Queries that work great in Oracle might cause havoc in Teradata and the reverse.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Apr 2019 16:11:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-how-to-make-it-write-proper-SQL-that-do-not-degrade/m-p/548264#M152015</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-04-03T16:11:37Z</dc:date>
    </item>
  </channel>
</rss>

