<?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: How to optimize the amount of db connections being opened in proc sql? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-optimize-the-amount-of-db-connections-being-opened-in/m-p/858162#M339065</link>
    <description>&lt;P&gt;It would be a lot more efficient just to query an Oracle dictionary table to see if tables exist or not:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname myoracle oracle noprompt = &amp;lt;Oracle connection string&amp;gt;;

proc sql;
  connect using myoracle;
  select * from connection to myoracle
  (SELECT TABLE_NAME 
FROM ALL_TABLES 
WHERE TABLE_NAME like '%OLDTABLE%'
);
quit; &lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 09 Feb 2023 23:52:38 GMT</pubDate>
    <dc:creator>SASKiwi</dc:creator>
    <dc:date>2023-02-09T23:52:38Z</dc:date>
    <item>
      <title>How to optimize the amount of db connections being opened in proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-optimize-the-amount-of-db-connections-being-opened-in/m-p/858007#M339005</link>
      <description>&lt;P&gt;Hello experts,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, in order to check whether a table exists or not and then create a new table, I have been doing the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%IF %SYSFUNC (EXIST (foo.bar)) %THEN %DO;
&amp;nbsp;&amp;nbsp;&amp;nbsp; PROC SQL NOPRINT;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DROP TABLE foo.bar;
&amp;nbsp;&amp;nbsp;&amp;nbsp; QUIT;
&amp;nbsp; %END;
&lt;BR /&gt;PROC SQL NOPRINT;
&amp;nbsp;&amp;nbsp;&amp;nbsp; CONNECT TO ORACLE AS ORA (&amp;amp;STRING_CONN.);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; execute by ora (
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table foo.bar as select * from foo.oldtable&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; );
&amp;nbsp;&amp;nbsp;&amp;nbsp; DISCONNECT FROM ORA;

QUIT;


%IF %SYSFUNC (EXIST (foo.bar2)) %THEN
%DO;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PROC SQL;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DROP TABLE foo.bar2;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; QUIT;
%END;

PROC SQL NOPRINT;
&amp;nbsp;&amp;nbsp;&amp;nbsp; CONNECT TO ORACLE AS ORA (&amp;amp;STRING_CONN.);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; execute by ora (
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table foo.bar2 as select * from foo.oldtable2&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; );
&amp;nbsp;&amp;nbsp;&amp;nbsp; DISCONNECT FROM ORA;

QUIT;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there any way to optimize the amount of connections being opened and use one proc sql?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have been using explicit passthru to create new tables but I haven't found any way to incorporate the IF in a better way so I can group this code in one proc sql.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2023 12:51:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-optimize-the-amount-of-db-connections-being-opened-in/m-p/858007#M339005</guid>
      <dc:creator>bsas94</dc:creator>
      <dc:date>2023-02-09T12:51:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to optimize the amount of db connections being opened in proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-optimize-the-amount-of-db-connections-being-opened-in/m-p/858019#M339009</link>
      <description>&lt;P&gt;If I were doing this, I would assign a libref with a LIBNAME statement and use PROC FEDSQL to do the deed. Explicit pass-through is a one-liner in FedSQL. For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname ora path=&amp;amp;oraclePath schema=foo user=&amp;amp;OraUser pw=OraPW;

proc FedSQL;
/* Implicit pass-through, FORCE ignores errors if table exists */
drop table ora.bar force; 
/* Explicit pass-through by referencing a libref as the alias */
execute (create table foo.bar as select * from foo.oldTable) by ora;
quit;


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2023 13:36:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-optimize-the-amount-of-db-connections-being-opened-in/m-p/858019#M339009</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2023-02-09T13:36:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to optimize the amount of db connections being opened in proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-optimize-the-amount-of-db-connections-being-opened-in/m-p/858162#M339065</link>
      <description>&lt;P&gt;It would be a lot more efficient just to query an Oracle dictionary table to see if tables exist or not:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname myoracle oracle noprompt = &amp;lt;Oracle connection string&amp;gt;;

proc sql;
  connect using myoracle;
  select * from connection to myoracle
  (SELECT TABLE_NAME 
FROM ALL_TABLES 
WHERE TABLE_NAME like '%OLDTABLE%'
);
quit; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Feb 2023 23:52:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-optimize-the-amount-of-db-connections-being-opened-in/m-p/858162#M339065</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-02-09T23:52:38Z</dc:date>
    </item>
  </channel>
</rss>

