<?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: Long time query running in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Long-time-query-running/m-p/851087#M336358</link>
    <description>&lt;P&gt;The SQL server&amp;nbsp;&lt;EM&gt;table&lt;/EM&gt; is not sorted, but its&amp;nbsp;&lt;EM&gt;contents&lt;/EM&gt; are sorted by SQL Server before being sent to SAS. This is what takes so long.&lt;/P&gt;</description>
    <pubDate>Sun, 25 Dec 2022 22:02:42 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-12-25T22:02:42Z</dc:date>
    <item>
      <title>Long time query running</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Long-time-query-running/m-p/851073#M336350</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I am running simple proc sort on a big data set that is located in a permanent library.&lt;/P&gt;
&lt;P&gt;It took more than 9 hours to complete this simple query so something is wrong here...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Please note that the WHERE statement is working on sas date variable called Update_date.&lt;/P&gt;
&lt;P&gt;My questions:&lt;/P&gt;
&lt;P&gt;Why did it happen?&lt;/P&gt;
&lt;P&gt;What is the solution for it?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let mon=2212;&lt;BR /&gt;&lt;BR /&gt;%let month = %substr(&amp;amp;mon,3,2);&lt;BR /&gt;%put &amp;amp;month;&lt;BR /&gt;%let year=20%substr(&amp;amp;mon,1,2);&lt;BR /&gt;%put &amp;amp;year;&lt;BR /&gt;&lt;BR /&gt;proc sort data=ENGINALB.ACCOUNT_MONTHLY_DATA(Where=(UPDATE_DATE  ne '16MAY2022'd &lt;BR /&gt;AND year(UPDATE_DATE)=&amp;amp;year. &lt;BR /&gt;AND month(UPDATE_DATE)=&amp;amp;month.))
out=ACCOUNT_MONTHLY_DATA_RF_CS_12;
by   UPDATE_DATE    FK_APPLICATION       FK_MONTHLY_DATA_ACCOUNT    REFERENCE_DATE  ;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the Log related to this query&lt;/P&gt;
&lt;PRE&gt;NOTE: Sorting was performed by the data source.
NOTE: There were 23734185 observations read from the data set ENGINALB.ACCOUNT_MONTHLY_DATA_RF_CS.
      WHERE (UPDATE_DATE not = '16MAY2022'D) and (YEAR(UPDATE_DATE)=2022) and (MONTH(UPDATE_DATE)=12);
NOTE: The data set WORK.ACCOUNT_MONTHLY_DATA_RF_CS_12 has 23734185 observations and 75 variables.
NOTE: Compressing data set WORK.ACCOUNT_MONTHLY_DATA_RF_CS_12 decreased size by 96.37 percent. 
      Compressed is 123105 pages; un-compressed would require 3390599 pages.
NOTE: PROCEDURE SORT used (Total process time):
      real time           9:56.82
      user cpu time       5:37.08
      system cpu time     11.28 seconds
      memory              1599.25k
      OS Memory           22176.00k
      Timestamp           12/25/2022 12:07:04 PM
      Step Count                        13  Switch Count  1
      Page Faults                       0
      Page Reclaims                     6542
      Page Swaps                        0
      Voluntary Context Switches        53563
      Involuntary Context Switches      857
      Block Input Operations            0
      Block Output Operations           0
      


NOTE: Missing values were generated as a result of performing an operation on missing values.
      Each place is given by: (Number of times) at (Line):(Column).
      51215 at 26:24   679 at 26:76     679 at 26:184    679 at 26:201    
NOTE: There were 23734185 observations read from the data set WORK.ACCOUNT_MONTHLY_DATA_RF_CS_12.&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I run it in another way then it took very short time&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data ACCOUNT_MONTHLY_DATA_RF_CS_12(Where=(UPDATE_DATE  ne '16MAY2022'd ));
SET ENGINALB.ACCOUNT_MONTHLY_DATA_RF_CS(Where=(
year(UPDATE_DATE)=&amp;amp;year.
AND month(UPDATE_DATE)=&amp;amp;month.));
Run;

proc sort data=ACCOUNT_MONTHLY_DATA_RF_CS_12;
by   UPDATE_DATE    FK_APPLICATION       FK_MONTHLY_DATA_ACCOUNT    REFERENCE_DATE  ;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Why this query is much quicker than the first one?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 25 Dec 2022 18:38:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Long-time-query-running/m-p/851073#M336350</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2022-12-25T18:38:22Z</dc:date>
    </item>
    <item>
      <title>Re: Long time query running</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Long-time-query-running/m-p/851076#M336352</link>
      <description>&lt;P&gt;Which engine does your library ENGINALB use? Run&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname enginalb list;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and post the log..&lt;/P&gt;</description>
      <pubDate>Sun, 25 Dec 2022 20:43:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Long-time-query-running/m-p/851076#M336352</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-12-25T20:43:03Z</dc:date>
    </item>
    <item>
      <title>Re: Long time query running</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Long-time-query-running/m-p/851077#M336353</link>
      <description>&lt;P&gt;Please post the log of your second faster run. Comparing the user CPU time would be useful.;&lt;/P&gt;</description>
      <pubDate>Sun, 25 Dec 2022 21:05:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Long-time-query-running/m-p/851077#M336353</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-12-25T21:05:22Z</dc:date>
    </item>
    <item>
      <title>Re: Long time query running</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Long-time-query-running/m-p/851078#M336354</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The initial Note "Sorting was performed by the data source" is probably the clue here. You do not specify the data location, but it might be a database system residing on a server without sufficient memory to perform the sort. This would explain the petter performance when the sorting is done in&amp;nbsp;SAS.&lt;/P&gt;</description>
      <pubDate>Sun, 25 Dec 2022 21:10:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Long-time-query-running/m-p/851078#M336354</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2022-12-25T21:10:45Z</dc:date>
    </item>
    <item>
      <title>Re: Long time query running</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Long-time-query-running/m-p/851082#M336355</link>
      <description>&lt;P&gt;Here is the Log after run : libname enginalb list;&lt;/P&gt;
&lt;PRE&gt;1                                                          The SAS System                            20:18 Sunday, December 25, 2022

1          ;*';*";*/;quit;run;
2          OPTIONS PAGENO=MIN;
3          %LET _CLIENTTASKLABEL='A';
4          %LET _CLIENTPROCESSFLOWNAME='Process Flow';
5          %LET _CLIENTPROJECTPATH='';
6          %LET _CLIENTPROJECTPATHHOST='';
7          %LET _CLIENTPROJECTNAME='';
8          %LET _SASPROGRAMFILE='K:\RRR\A.sas';
9          %LET _SASPROGRAMFILEHOST='VSK2H010A3003';
10         
11         ODS _ALL_ CLOSE;
12         OPTIONS DEV=PNG;
13         GOPTIONS XPIXELS=0 YPIXELS=0;
14         FILENAME EGSR TEMP;
15         ODS tagsets.sasreport13(ID=EGSR) FILE=EGSR
16             STYLE=HTMLBlue
17             STYLESHEET=(URL="file:///C:/Program%20Files/SASHome/SASEnterpriseGuide/7.1/Styles/HTMLBlue.css")
18             NOGTITLE
19             NOGFOOTNOTE
20             GPATH=&amp;amp;sasworklocation
21             ENCODING=UTF8
22             options(rolap="on")
23         ;
NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR
24         
25         GOPTIONS ACCESSIBLE;
26         libname enginalb list;
NOTE: Libref=   ENGINALB 
      Scope=    Object Server
      Engine=   SQLSVR
      Physical Name= EnginalBatch
      Schema/Owner= dbo
27         
28         
29         GOPTIONS NOACCESSIBLE;
30         %LET _CLIENTTASKLABEL=;
31         %LET _CLIENTPROCESSFLOWNAME=;
32         %LET _CLIENTPROJECTPATH=;
33         %LET _CLIENTPROJECTPATHHOST=;
34         %LET _CLIENTPROJECTNAME=;
35         %LET _SASPROGRAMFILE=;
36         %LET _SASPROGRAMFILEHOST=;
37         
38         ;*';*";*/;quit;run;
39         ODS _ALL_ CLOSE;
40         
41         
42         QUIT; RUN;
43         
&lt;/PRE&gt;</description>
      <pubDate>Sun, 25 Dec 2022 21:47:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Long-time-query-running/m-p/851082#M336355</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2022-12-25T21:47:45Z</dc:date>
    </item>
    <item>
      <title>Re: Long time query running</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Long-time-query-running/m-p/851085#M336356</link>
      <description>&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;I want to understand please about way1:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;Is the sort done on the permanent data set (libname&amp;nbsp;&lt;CODE class=" language-sas"&gt;ENGINALB)&amp;nbsp;&amp;nbsp;and&amp;nbsp;only&amp;nbsp;then&amp;nbsp;it&amp;nbsp;is&amp;nbsp;saved&amp;nbsp;in&amp;nbsp;work&amp;nbsp;library?&lt;/CODE&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;CODE class=" language-sas"&gt;I&amp;nbsp;was&amp;nbsp;sure&amp;nbsp;that&amp;nbsp;first&amp;nbsp;create&amp;nbsp;data&amp;nbsp;set&amp;nbsp;in&amp;nbsp;work&amp;nbsp;library&amp;nbsp;and&amp;nbsp;only&amp;nbsp;then&amp;nbsp;sort&amp;nbsp;the&amp;nbsp;data.&lt;/CODE&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;CODE class=" language-sas"&gt;I&amp;nbsp;also&amp;nbsp;think&amp;nbsp;that&amp;nbsp;it&amp;nbsp;is&amp;nbsp;not&amp;nbsp;allowed&amp;nbsp;to&amp;nbsp;perform&amp;nbsp;sort&amp;nbsp;on&amp;nbsp;permanent&amp;nbsp;data&amp;nbsp;set&amp;nbsp;(by&amp;nbsp;admin&amp;nbsp;restrictions).&lt;/CODE&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let mon=2212;
%let month = %substr(&amp;amp;mon,3,2);
%put &amp;amp;month;
%let year=20%substr(&amp;amp;mon,1,2);
%put &amp;amp;year;

/***Way1-Very long run time***/
/***Way1-Very long run time***/
/***Way1-Very long run time***/
proc sort data=ENGINALB.ACCOUNT_MONTHLY_DATA(Where=(UPDATE_DATE  ne '16MAY2022'd AND year(UPDATE_DATE)=&amp;amp;year. AND month(UPDATE_DATE)=&amp;amp;month.))
out=ACCOUNT_MONTHLY_DATA_RF_CS_12;
by   UPDATE_DATE    FK_APPLICATION       FK_MONTHLY_DATA_ACCOUNT    REFERENCE_DATE  ;
Run;

/***Way2-quick run time***/
/***Way2-quick run time***/
/***Way2-quick run time***/
Data ACCOUNT_MONTHLY_DATA_RF_CS_12(Where=(UPDATE_DATE  ne '16MAY2022'd ));
SET ENGINALB.ACCOUNT_MONTHLY_DATA_RF_CS(Where=(
year(UPDATE_DATE)=&amp;amp;year.
AND month(UPDATE_DATE)=&amp;amp;month.));
Run;

proc sort data=ACCOUNT_MONTHLY_DATA_RF_CS_12;
by   UPDATE_DATE    FK_APPLICATION       FK_MONTHLY_DATA_ACCOUNT    REFERENCE_DATE  ;
Run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 25 Dec 2022 21:57:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Long-time-query-running/m-p/851085#M336356</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2022-12-25T21:57:47Z</dc:date>
    </item>
    <item>
      <title>Re: Long time query running</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Long-time-query-running/m-p/851086#M336357</link>
      <description>&lt;P&gt;As &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12887"&gt;@ErikLund_Jensen&lt;/a&gt;&amp;nbsp;already suspected, your SQL server seems to be seriously undersized for the data.&lt;/P&gt;
&lt;P&gt;Move all processing to SAS.&lt;/P&gt;</description>
      <pubDate>Sun, 25 Dec 2022 21:58:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Long-time-query-running/m-p/851086#M336357</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-12-25T21:58:37Z</dc:date>
    </item>
    <item>
      <title>Re: Long time query running</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Long-time-query-running/m-p/851087#M336358</link>
      <description>&lt;P&gt;The SQL server&amp;nbsp;&lt;EM&gt;table&lt;/EM&gt; is not sorted, but its&amp;nbsp;&lt;EM&gt;contents&lt;/EM&gt; are sorted by SQL Server before being sent to SAS. This is what takes so long.&lt;/P&gt;</description>
      <pubDate>Sun, 25 Dec 2022 22:02:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Long-time-query-running/m-p/851087#M336358</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-12-25T22:02:42Z</dc:date>
    </item>
    <item>
      <title>Re: Long time query running</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Long-time-query-running/m-p/851089#M336359</link>
      <description>As I understand the permanent data set is located in SQL SERVER data base.&lt;BR /&gt;Is it the reason for the long run of proc sort?&lt;BR /&gt;If the permanent data set  was located in SAS server, then it wouldn't take long run?&lt;BR /&gt;&lt;BR /&gt;What do you mean when you say that contents are sorted by sql server but table is not sorted by sql server?&lt;BR /&gt;(What does it mean contents?)As I know sort is done on the data ...&lt;BR /&gt;</description>
      <pubDate>Sun, 25 Dec 2022 22:08:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Long-time-query-running/m-p/851089#M336359</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2022-12-25T22:08:33Z</dc:date>
    </item>
    <item>
      <title>Re: Long time query running</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Long-time-query-running/m-p/851093#M336361</link>
      <description>&lt;P&gt;Is the sort done on sql server ? Why?&lt;/P&gt;</description>
      <pubDate>Sun, 25 Dec 2022 22:14:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Long-time-query-running/m-p/851093#M336361</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2022-12-25T22:14:38Z</dc:date>
    </item>
    <item>
      <title>Re: Long time query running</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Long-time-query-running/m-p/851095#M336362</link>
      <description>&lt;P&gt;By default SAS will pass processing back to the external database you are reading as it is usually more efficient to do it that way.&lt;/P&gt;</description>
      <pubDate>Sun, 25 Dec 2022 22:38:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Long-time-query-running/m-p/851095#M336362</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-12-25T22:38:35Z</dc:date>
    </item>
    <item>
      <title>Re: Long time query running</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Long-time-query-running/m-p/851097#M336364</link>
      <description>&lt;P&gt;The table in the database will stay as it is, but the data contained in it will be sorted (in-memory or in temporary space when out of memory) by the database server before being sent to SAS.&lt;/P&gt;
&lt;P&gt;Explicitly sorting in SAS avoids this, and the DB needs only do a single sequential read while applying the WHERE.&lt;/P&gt;</description>
      <pubDate>Sun, 25 Dec 2022 23:01:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Long-time-query-running/m-p/851097#M336364</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-12-25T23:01:27Z</dc:date>
    </item>
    <item>
      <title>Re: Long time query running</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Long-time-query-running/m-p/851100#M336367</link>
      <description>&lt;P&gt;I'd also suggest trying a different WHERE clause to see if that makes any difference:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where UPDATE_DATE between '01Dec2022'd and '31Dec2022'd&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 25 Dec 2022 23:48:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Long-time-query-running/m-p/851100#M336367</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-12-25T23:48:58Z</dc:date>
    </item>
  </channel>
</rss>

