<?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: Proc SQL - Query Taking Longer time - Query Need to Optimize - Need Expert Help!! in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Query-Taking-Longer-time-Query-Need-to-Optimize-Need/m-p/944391#M370020</link>
    <description>&lt;P&gt;MariaDB database.&lt;/P&gt;</description>
    <pubDate>Wed, 18 Sep 2024 12:21:53 GMT</pubDate>
    <dc:creator>amitbjambhulkar</dc:creator>
    <dc:date>2024-09-18T12:21:53Z</dc:date>
    <item>
      <title>Proc SQL - Query Taking Longer time - Query Need to Optimize - Need Expert Help!!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Query-Taking-Longer-time-Query-Need-to-Optimize-Need/m-p/944351#M370010</link>
      <description>&lt;DIV&gt;Hello,&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;I am trying to write the below query which taking longer time around 11 hours &amp;amp; 30 mins to complete. Is their any other way where it can run the query faster way. Any help / suggestion will be really helpful for me. Thanks.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;proc sql noprint;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; select&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; max(datepart(tran_datetime)) format date9.&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; into :end_ugt_hist&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; from DBA.sas_max_site_datetimes&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; where site = "SKY" and&amp;nbsp; "15SEP2020"d &amp;lt;= datepart(tran_datetime) &amp;lt;= today();&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;quit;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; real time&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;11:33:01.77&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; cpu time&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 40.52 seconds&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Amit&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2024 07:15:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Query-Taking-Longer-time-Query-Need-to-Optimize-Need/m-p/944351#M370010</guid>
      <dc:creator>amitbjambhulkar</dc:creator>
      <dc:date>2024-09-18T07:15:08Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL - Query Taking Longer time - Query Need to Optimize - Need Expert Help!!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Query-Taking-Longer-time-Query-Need-to-Optimize-Need/m-p/944360#M370012</link>
      <description>&lt;P&gt;I think the wasting time is not from SAS side, it should be from DataBase side (&lt;SPAN&gt;DBA.sas_max_site_datetimes&lt;/SPAN&gt;).&lt;/P&gt;
&lt;P&gt;Try to reduce the process time at DBA side by LIBNAME's option :&amp;nbsp; read_buff=10000 ,insert_buff=10000 ,dbcommit=0,bulkload=yes.&lt;/P&gt;
&lt;P&gt;And&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;&amp;nbsp;knew more things about this topic .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or try to use pass-through method to run this SQL.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2024 08:47:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Query-Taking-Longer-time-Query-Need-to-Optimize-Need/m-p/944360#M370012</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-09-18T08:47:10Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL - Query Taking Longer time - Query Need to Optimize - Need Expert Help!!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Query-Taking-Longer-time-Query-Need-to-Optimize-Need/m-p/944361#M370013</link>
      <description>&lt;P&gt;In the WHERE clause, use datetime &lt;EM&gt;constants&lt;/EM&gt; (replace the call of TODAY() with the result of DATETIME() stored in a macro variable, so you can have no function calls at all in your WHERE.&lt;/P&gt;
&lt;P&gt;Use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options fullstimer;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to see the relationship between real time and CPU usage; a library name of DBA points to a connection to a remote database, so either the network connection and/or the configuration of the LIBNAME might be the culprit.&lt;/P&gt;
&lt;P&gt;Also take a look at the&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/acreldb/n0732u1mr57ycrn1urf24gzo38sc.htm" target="_blank" rel="noopener"&gt;SASTRACE=&lt;/A&gt;&amp;nbsp;system option which can show you which parts if the query are offloaded to the remote DB.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2024 08:56:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Query-Taking-Longer-time-Query-Need-to-Optimize-Need/m-p/944361#M370013</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-09-18T08:56:14Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL - Query Taking Longer time - Query Need to Optimize - Need Expert Help!!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Query-Taking-Longer-time-Query-Need-to-Optimize-Need/m-p/944388#M370019</link>
      <description>&lt;P&gt;It's likely that SAS can't translate the full SQL query to the database SQL syntax and though a lot of data gets first pulled to the SAS side before the where clause executes.&lt;/P&gt;
&lt;P&gt;What database are you interfacing with? The SAS documentation for the access engine for your DB documents which SAS functions can get pushed to the DB side.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I obviously couldn't fully test it but I believe below code should work and perform better.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let low_dttm   =15SEP2020:00:00:00;
%let high_dttm  =%sysfunc(intnx(dtday,%sysfunc(datetime()),1,b),datetime18.);

proc sql noprint;
  select datepart(tran_datetime)) format=date9. into :end_ugt_hist
  from
    (
      select max(tran_datetime)
      from DBA.sas_max_site_datetimes 
      where site = "SKY" and  "&amp;amp;low_dttm"dt &amp;lt;= tran_datetime &amp;lt; "&amp;amp;high_dttm"dt
    )
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2024 12:21:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Query-Taking-Longer-time-Query-Need-to-Optimize-Need/m-p/944388#M370019</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-09-18T12:21:56Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL - Query Taking Longer time - Query Need to Optimize - Need Expert Help!!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Query-Taking-Longer-time-Query-Need-to-Optimize-Need/m-p/944391#M370020</link>
      <description>&lt;P&gt;MariaDB database.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2024 12:21:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Query-Taking-Longer-time-Query-Need-to-Optimize-Need/m-p/944391#M370020</guid>
      <dc:creator>amitbjambhulkar</dc:creator>
      <dc:date>2024-09-18T12:21:53Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL - Query Taking Longer time - Query Need to Optimize - Need Expert Help!!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Query-Taking-Longer-time-Query-Need-to-Optimize-Need/m-p/944392#M370021</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/9428"&gt;@amitbjambhulkar&lt;/a&gt;&amp;nbsp;Try the code I just posted (latest update). It should work for ODBC.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2024 12:44:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Query-Taking-Longer-time-Query-Need-to-Optimize-Need/m-p/944392#M370021</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-09-18T12:44:51Z</dc:date>
    </item>
  </channel>
</rss>

