<?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 make SQL query faster? in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-make-SQL-query-faster/m-p/563061#M33856</link>
    <description>&lt;P&gt;Welcome to the SAS Community.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There's a lot going on in your query and you seem to have only one source SAS table. How many rows does it have?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suggest you start by removing the sub-query join and time how long the remaining query takes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Due you really need to use DISTINCT? If your GROUP BY's are working correctly these shouldn't be necessary.&lt;/P&gt;</description>
    <pubDate>Sat, 01 Jun 2019 00:29:32 GMT</pubDate>
    <dc:creator>SASKiwi</dc:creator>
    <dc:date>2019-06-01T00:29:32Z</dc:date>
    <item>
      <title>How to make SQL query faster?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-make-SQL-query-faster/m-p/562891#M33849</link>
      <description>&lt;P&gt;Currently takes about 1.5 hours to run.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE WORK.QUERY_MedicalTable AS&lt;/P&gt;&lt;P&gt;SELECT DISTINCT&lt;BR /&gt;(CASE WHEN MISSING(SUBSTR(t1.SVCCD,1,3)) THEN t2.SOURCE2 ELSE (SUBSTR(t1.SVCCD,1,3)) END) AS SOURCE&lt;BR /&gt;,t1.LOC_ID_CD AS PRIOR_LOCATION&lt;BR /&gt;,(SUM(t1.SVC_UNT_QT)/3) AS PRIOR_QUANTITY_AVG&lt;BR /&gt;,t2.LOC_ID_CD AS CURRENT_MONTH_LOCATIONS&lt;BR /&gt;,t2.CURRENT_MONTH_QUANTITY&lt;BR /&gt;,((t2.CURRENT_MONTH_QUANTITY - (SUM(t1.SVC_UNT_QT)/3))/ (SUM(t1.SVC_UNT_QT))) AS VARIANCE&lt;BR /&gt;FROM MedicalTable t1&lt;BR /&gt;FULL JOIN (SELECT DISTINCT&lt;BR /&gt;SUBSTR(t2a.SVCCD,1,3) AS SOURCE2&lt;BR /&gt;,t2a.LOC_ID_CD&lt;BR /&gt;,SUM(t2a.SVC_UNT_QT) AS CURRENT_MONTH_QUANTITY&lt;BR /&gt;FROM MedicalTable t2a&lt;BR /&gt;WHERE t2a.YR_NB = 2019 AND t2a.MM_NB = 4&amp;nbsp;&amp;nbsp;&lt;BR /&gt;GROUP BY SUBSTR(t2a.SVCCD,1,3), t2a.LOC_ID_CD) t2&lt;BR /&gt;ON (t1.LOC_ID_CD = t2.LOC_ID_CD AND SUBSTR(t1.SVCCD,1,3) = t2.SOURCE2)&lt;BR /&gt;WHERE t1.YR_NB = 2019 AND t1.MM_NB BETWEEN 1 AND 3 &amp;nbsp;&lt;BR /&gt;GROUP BY SUBSTR(t1.SVCCD,1,3), t1.LOC_ID_CD, t2.LOC_ID_CD, t2.SOURCE2&lt;BR /&gt;HAVING (((t2.CURRENT_MONTH_QUANTITY - (SUM(t1.SVC_UNT_QT)/3))/ (SUM(t1.SVC_UNT_QT))) NOT BETWEEN .0000001 AND .049999)&lt;BR /&gt;OR (((t2.CURRENT_MONTH_QUANTITY - (SUM(t1.SVC_UNT_QT)/3))/ (SUM(t1.SVC_UNT_QT))) NOT BETWEEN -.0000001 AND -.049999)&lt;BR /&gt;ORDER BY SUBSTR(t1.SVCCD,1,3) ASC , t1.LOC_ID_CD ASC;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2019 15:47:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-make-SQL-query-faster/m-p/562891#M33849</guid>
      <dc:creator>nbknoid</dc:creator>
      <dc:date>2019-05-31T15:47:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to make SQL query faster?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-make-SQL-query-faster/m-p/563061#M33856</link>
      <description>&lt;P&gt;Welcome to the SAS Community.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There's a lot going on in your query and you seem to have only one source SAS table. How many rows does it have?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suggest you start by removing the sub-query join and time how long the remaining query takes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Due you really need to use DISTINCT? If your GROUP BY's are working correctly these shouldn't be necessary.&lt;/P&gt;</description>
      <pubDate>Sat, 01 Jun 2019 00:29:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-make-SQL-query-faster/m-p/563061#M33856</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-06-01T00:29:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to make SQL query faster?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-make-SQL-query-faster/m-p/563208#M33863</link>
      <description>&lt;P&gt;Also, provide the log with FULLSTIMER option enabled, where you can see whether your performance is I/O or CPU bound.&lt;/P&gt;
&lt;P&gt;If you have any indexes use MSGLEVEL=I to see if any is being used.&lt;/P&gt;
&lt;P&gt;Executing SQL with _method gives hints on how PROC SQL is evaluating and plan the query.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jun 2019 09:23:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-make-SQL-query-faster/m-p/563208#M33863</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2019-06-03T09:23:25Z</dc:date>
    </item>
  </channel>
</rss>

