<?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: Libname statement vs Pass thru query in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Libname-statement-vs-Pass-thru-query/m-p/791712#M253635</link>
    <description>&lt;P&gt;Not sure what the question is here.&lt;/P&gt;
&lt;P&gt;You can use a previously defined LIBREF with PROC SQL to connect to the database to push explicit query into the database&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname mydb oracle ..... ;
proc sql;
connect using mydb;
create table want as select * from connection to mydb
( select * from myschema.mytable)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 23 Jan 2022 16:31:19 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-01-23T16:31:19Z</dc:date>
    <item>
      <title>Libname statement vs Pass thru query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Libname-statement-vs-Pass-thru-query/m-p/791697#M253628</link>
      <description>&lt;P&gt;Hi Guys&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How to connect external databases using Libname statement which is better for optimizing code&amp;nbsp;&lt;/P&gt;
&lt;P&gt;liname statement or pass thru query&lt;/P&gt;</description>
      <pubDate>Sun, 23 Jan 2022 08:59:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Libname-statement-vs-Pass-thru-query/m-p/791697#M253628</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2022-01-23T08:59:58Z</dc:date>
    </item>
    <item>
      <title>Re: Libname statement vs Pass thru query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Libname-statement-vs-Pass-thru-query/m-p/791698#M253629</link>
      <description>&lt;P&gt;For the first part of your question: read the documentation.&lt;/P&gt;
&lt;P&gt;For the second part: If you have a task where the remote SQL provides a tool that has no counterpart in SAS (like using partitions), you need to use explicit pass-through. To compare implicit and explicit, see Maxim 4.&lt;/P&gt;</description>
      <pubDate>Sun, 23 Jan 2022 09:18:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Libname-statement-vs-Pass-thru-query/m-p/791698#M253629</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-01-23T09:18:10Z</dc:date>
    </item>
    <item>
      <title>Re: Libname statement vs Pass thru query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Libname-statement-vs-Pass-thru-query/m-p/791712#M253635</link>
      <description>&lt;P&gt;Not sure what the question is here.&lt;/P&gt;
&lt;P&gt;You can use a previously defined LIBREF with PROC SQL to connect to the database to push explicit query into the database&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname mydb oracle ..... ;
proc sql;
connect using mydb;
create table want as select * from connection to mydb
( select * from myschema.mytable)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 23 Jan 2022 16:31:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Libname-statement-vs-Pass-thru-query/m-p/791712#M253635</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-01-23T16:31:19Z</dc:date>
    </item>
    <item>
      <title>Re: Libname statement vs Pass thru query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Libname-statement-vs-Pass-thru-query/m-p/791807#M253684</link>
      <description>&lt;P&gt;I assume your question is: "Which is better for optimizing code - libname or passthrough SQL?".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That depends.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are obviously things that work better with pass through SQL, such as adding "FOR FETCH ONLY" when getting stuff from DB2 (can speed up things tremendously), or using hints in ORACLE, and a lot of other powerful stuff that various databases let you do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are also things that are a lot easier, and at time also faster, using libname access. Especially when you want to to use the sequential processing available in the SAS datastep, or you want to merge data from an SQL database with data from other sources.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One little hint about the latter: SAS has an implicit ORDER BY in setting data from SQL databases, so with code like this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname accts db2 schema=acct;

data x;
  merge work.recieved accts.ledger;
  by ledger_ID received_date;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The SQL statement executed behind the scenes will include an "ORDER BY ledger_ID recieved_date". If the DB2 table is indexed on these fields, this can be very fast. At times it may also work quite well without indexes, depending on the power of the database server.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In an example like the above, you may also want to put a WHERE clause on the DB2 table, if possible, to speed things up.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unless performance is a high priority, I would work with the type of connection that makes for the most readable code. Again, that depends on what you want to do, and how much the people who should maintain the code know about native SQL and about SAS.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jan 2022 10:26:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Libname-statement-vs-Pass-thru-query/m-p/791807#M253684</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2022-01-24T10:26:47Z</dc:date>
    </item>
  </channel>
</rss>

