<?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: Sorting problem in Proc SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sorting-problem-in-Proc-SQL/m-p/571166#M161114</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;:&lt;/P&gt;
&lt;P&gt;Apparently, much depends on the system set up. I ran my tests on the very laptop I'm typing this, a very old ThinkPad W520 i7 with SAS 9.4 1M4 under X64_7PRO, 2.4 GHz, 8G RAM, and 500G SSD. MEMSIZE=REALMEMSIZE=SORTSIZE=4G. My average figures over 10 runs (real time in seconds / memory in MB):&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;SORT (NOEQUALS): 5.3 / 1028&lt;/LI&gt;
&lt;LI&gt;SQL: 6.2 / 1027&lt;/LI&gt;
&lt;LI&gt;HASH: 4.6 / 32&lt;/LI&gt;
&lt;LI&gt;KEY-INDEX: 2.2 / 2&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 04 Jul 2019 07:52:38 GMT</pubDate>
    <dc:creator>hashman</dc:creator>
    <dc:date>2019-07-04T07:52:38Z</dc:date>
    <item>
      <title>Sorting problem in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-problem-in-Proc-SQL/m-p/571029#M161061</link>
      <description>&lt;P&gt;Hi SAS experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I use the sas studio background submit to run my code and here is the log:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;402        proc sql;
403        	create table xing.outp_serv_sort as
404        	select *
405        		from xing.outp_serv
406        		order by enrolid, svcdate;
ERROR: Sort execution failure.

NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
407        	
408        	/*remove duplicates w/ the same enrolid and svcdate*/
409        	create table xing.outp_serv_noduprecs1 as
410        	select distinct enrolid, svcdate
411        		from xing.outp_serv_sort
412        		order by enrolid, svcdate;
NOTE: Statement not executed due to NOEXEC option.
413        	
414        	/*remove duplicates w/ the same enrolid, svcdate, and procgrp*/
415        	create table xing.outp_serv_noduprecs2 as
416        	select distinct enrolid, svcdate, procgrp
417        		from xing.outp_serv_sort
418        		order by enrolid, svcdate, procgrp;
NOTE: Statement not executed due to NOEXEC option.
419        quit;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
      real time           1:39.93
      cpu time            38.82 seconds&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It says the sort execution failed (line 402 to 406). The table xing.outp_serv has more than 5 billion observations. Is it due to the table too big and cannot be sorted? How can I fix it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jul 2019 17:07:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-problem-in-Proc-SQL/m-p/571029#M161061</guid>
      <dc:creator>Xing</dc:creator>
      <dc:date>2019-07-03T17:07:32Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting problem in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-problem-in-Proc-SQL/m-p/571038#M161064</link>
      <description>&lt;P&gt;Please check this post and the reply (&lt;A href="https://communities.sas.com/t5/SAS-Procedures/ERROR-Sort-execution-failure-in-PROC-SQL/m-p/262581#M57675" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Procedures/ERROR-Sort-execution-failure-in-PROC-SQL/m-p/262581#M57675&lt;/A&gt;).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am quoting from the referred link, in the above post.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"&lt;/P&gt;&lt;P&gt;The SAS®&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;SORT and SQL procedures (PROC SORT and PROC SQL) might fail with these errors:&lt;/P&gt;&lt;DIV&gt;ERROR: Sort initialization failure.&lt;/DIV&gt;&lt;DIV&gt;ERROR: Sort execution failure.&lt;/DIV&gt;&lt;P&gt;Common reasons for these errors include the following:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;insufficient disk space available when required&lt;/LI&gt;&lt;LI&gt;insufficient memory available when required&lt;/LI&gt;&lt;LI&gt;insufficient UNIX user limits on system resource or disk quota&lt;/LI&gt;&lt;LI&gt;incorrect setting of a SAS system option or operating system parameter&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;"&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jul 2019 17:34:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-problem-in-Proc-SQL/m-p/571038#M161064</guid>
      <dc:creator>koyelghosh</dc:creator>
      <dc:date>2019-07-03T17:34:14Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting problem in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-problem-in-Proc-SQL/m-p/571125#M161090</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/278143"&gt;@Xing&lt;/a&gt;&amp;nbsp;:&lt;/P&gt;
&lt;P&gt;Your system resources are obviously inadequate for sorting the entire huge file&amp;nbsp;xing.outp_serv, so SQL fails on the first query.&lt;/P&gt;
&lt;P&gt;However, for the apparent results you are seeking - to wit, getting the sets of the unique values of the composite keys (enrolid, svcdate) and (enrolid, svcdate, procgrp) - your program does a lot of unnecessary work, and this is exactly where it bombs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need only 2 and 3 variables in the end, and yet you start by sorting the &lt;EM&gt;entire&lt;/EM&gt; file with all the (who knows how many) variables you have there. Truth be told, you don't need your query #1 at all: Queries #2 and #3 can run directly against the original xing.outp.serv file just fine all by themselves. Furthermore, you can drop the ORDER clauses in them, as the outputs will be in the required order by virtue of the internal algorithm behind the fulfilling of the DISTINCT request. Also, it's much more efficient to execute query #3 first and then run query #2 against its result set. In other words, this should work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;                                 
  create table xing.outp_serv_noduprecs2 as
  select distinct enrolid, svcdate, procgrp
  from   xing.outp_serv                    
  ;                                        
  create table xing.outp_serv_noduprecs1 as
  select distinct enrolid, svcdate         
  from   xing.outp_serv_noduprecs2         
  ;                                        
quit ;                                     
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2019 04:30:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-problem-in-Proc-SQL/m-p/571125#M161090</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-07-04T04:30:21Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting problem in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-problem-in-Proc-SQL/m-p/571130#M161092</link>
      <description>&lt;P&gt;Also, proc sort is more efficient at removing duplicates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data T;
  do I=1 to 5e2;
  do J=1 to 5e2;
  do K=1 to 1e2;
    output; 
  end; end; end;
run;

proc sort data=T(keep=I J) out=T1 nodupkey noequals; by I J; run;

proc sql; create table T2 as select unique I, J from T order by I, J; quit;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;NOTE: PROCEDURE SORT used (Total process time):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;real time 7.64 seconds&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;user cpu time 11.01 seconds&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;system cpu time 1.82 seconds&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;real time 10.50 seconds&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;user cpu time 12.26 seconds&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;system cpu time 4.04 seconds&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2019 05:08:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-problem-in-Proc-SQL/m-p/571130#M161092</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-07-04T05:08:43Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting problem in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-problem-in-Proc-SQL/m-p/571135#M161097</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/278143"&gt;@Xing&lt;/a&gt;&amp;nbsp;I have a suggestion, on similar lines to the responses given by other members.&lt;/P&gt;&lt;P&gt;Your first SQL step is likely to be the most costly. I see that you are feeding one SQL step into the other. If you are not using first SQL block anywhere else then I suggest you start with second (or may be even the third and last) SQL block and defer the ORDER BY to the third and last SQL block. I see that all you want is distinct values of enrolid, svcdate and procgrp in the end sorted by the same variables. The DISTINCT clause should work before ORDER BY and that way you will have less number of rows to sort.&lt;/P&gt;&lt;P&gt;In summary defer the ORDER BY as late as possible.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I might be wrong here but worth a try.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2019 05:29:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-problem-in-Proc-SQL/m-p/571135#M161097</guid>
      <dc:creator>koyelghosh</dc:creator>
      <dc:date>2019-07-04T05:29:04Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting problem in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-problem-in-Proc-SQL/m-p/571145#M161100</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;:&lt;/P&gt;
&lt;P&gt;NOEQUALS rules. But with keys like these, key-indexing will blow the doors off everything else:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data T1 ;                       
  array h [250500] _temporary_ ;
  set T ;                       
  _n_ = I * 5e2 + J ;           
  if not h[_n_] ;              
  h[_n_] = 1 ;                 
run ;                           
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The much more versatile (i.e. not relying on key properties) hash object is no slouch, either:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data T1 ;                    
  if _n_ = 1 then do ;       
    dcl hash h (hashexp:20) ;
    h.definekey ("I", "J") ; 
    h.definedone () ;        
  end ;                      
  set T ;                    
  if h.check() ne 0 ;        
  h.add() ;                  
run ;                        
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also, in my tests both SORT and SQL grab over 1G of RAM to get the job done, while the key-indexing and hash object use 2M and 32M, respectively. I haven't tried SORT with SORTSIZE (or SQL with REALMEMSIZE) limited to 32M , but I'll bet that with that limit and resulting swapping, both will drag their feet for a whole lot longer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2019 06:09:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-problem-in-Proc-SQL/m-p/571145#M161100</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-07-04T06:09:02Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting problem in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-problem-in-Proc-SQL/m-p/571159#M161108</link>
      <description>&lt;P&gt;I just ran a test of all four methods, and got this log:&lt;/P&gt;
&lt;PRE&gt;36         proc sort data=T(keep=I J) out=T1 nodupkey noequals; by I J; run;

NOTE: 24750000 observations with duplicate key values were deleted.
2                                                          Das SAS System                               08:06 Thursday, July 4, 2019

NOTE: The data set WORK.T1 has 250000 observations and 2 variables.
NOTE: PROZEDUR SORT used (Total process time):
      real time           5.21 seconds
      user cpu time       2.93 seconds
      system cpu time     0.08 seconds
      memory              193709.28k
      OS Memory           217440.00k
      Timestamp           04.07.2019 09:10:15 vorm.
      Step Count                        12  Switch Count  11
      Page Faults                       0
      Page Reclaims                     50380
      Page Swaps                        0
      Voluntary Context Switches        602
      Involuntary Context Switches      918
      Block Input Operations            0
      Block Output Operations           0
      

37         
38         proc sql;
38       !           create table T2 as select unique I, J from T order by I, J;
NOTE: Table WORK.T2 created, with 250000 rows and 2 columns.

38       !                                                                       quit;
NOTE: PROZEDUR SQL used (Total process time):
      real time           15.53 seconds
      user cpu time       5.09 seconds
      system cpu time     0.67 seconds
      memory              193332.84k
      OS Memory           216380.00k
      Timestamp           04.07.2019 09:10:31 vorm.
      Step Count                        13  Switch Count  11
      Page Faults                       0
      Page Reclaims                     50249
      Page Swaps                        0
      Voluntary Context Switches        684
      Involuntary Context Switches      1897
      Block Input Operations            0
      Block Output Operations           0
      

39         
40         data T3 ;
41           array h [250500] _temporary_ ;
42           set T ;
43           _n_ = I * 5e2 + J ;
44           if not h[_n_] ;
45           h[_n_] = 1 ;
46         run ;

NOTE: There were 25000000 observations read from the data set WORK.T.
NOTE: The data set WORK.T3 has 250000 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           4.97 seconds
      user cpu time       1.37 seconds
      system cpu time     0.07 seconds
      memory              2602.43k
      OS Memory           26704.00k
3                                                          Das SAS System                               08:06 Thursday, July 4, 2019

      Timestamp           04.07.2019 09:10:36 vorm.
      Step Count                        14  Switch Count  2
      Page Faults                       0
      Page Reclaims                     495
      Page Swaps                        0
      Voluntary Context Switches        11
      Involuntary Context Switches      326
      Block Input Operations            0
      Block Output Operations           0
      

47         
48         data T4 ;
49           if _n_ = 1 then do ;
50             dcl hash h (hashexp:20) ;
51             h.definekey ("I", "J") ;
52             h.definedone () ;
53           end ;
54           set T ;
55           if h.check() ne 0 ;
56           h.add() ;
57         run ;

NOTE: There were 25000000 observations read from the data set WORK.T.
NOTE: The data set WORK.T4 has 250000 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           13.26 seconds
      user cpu time       3.61 seconds
      system cpu time     0.07 seconds
      memory              33555.28k
      OS Memory           57588.00k
      Timestamp           04.07.2019 09:10:49 vorm.
      Step Count                        15  Switch Count  26
      Page Faults                       2
      Page Reclaims                     7709
      Page Swaps                        0
      Voluntary Context Switches        81
      Involuntary Context Switches      1316
      Block Input Operations            0
      Block Output Operations           0
 &lt;/PRE&gt;
&lt;P&gt;(performed on a pSeries with two POWER7 (or -8) cores, and a solid SAN for storage; also there's a severe MEMSIZE limit to enable lots of parallel SAS processes without paging)&lt;/P&gt;
&lt;P&gt;SORT and the array method are close, strongly beating both the hash and the SQL.&lt;/P&gt;
&lt;P&gt;Since the SORT has to make the least assumptions (read: none) about expected size, and needs the simplest code, it's still the preferred tool.&lt;/P&gt;
&lt;P&gt;Bottom line (for me): if you need a certain order, PROC SORT rules the roost.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2019 07:19:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-problem-in-Proc-SQL/m-p/571159#M161108</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-07-04T07:19:14Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting problem in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-problem-in-Proc-SQL/m-p/571166#M161114</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;:&lt;/P&gt;
&lt;P&gt;Apparently, much depends on the system set up. I ran my tests on the very laptop I'm typing this, a very old ThinkPad W520 i7 with SAS 9.4 1M4 under X64_7PRO, 2.4 GHz, 8G RAM, and 500G SSD. MEMSIZE=REALMEMSIZE=SORTSIZE=4G. My average figures over 10 runs (real time in seconds / memory in MB):&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;SORT (NOEQUALS): 5.3 / 1028&lt;/LI&gt;
&lt;LI&gt;SQL: 6.2 / 1027&lt;/LI&gt;
&lt;LI&gt;HASH: 4.6 / 32&lt;/LI&gt;
&lt;LI&gt;KEY-INDEX: 2.2 / 2&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2019 07:52:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-problem-in-Proc-SQL/m-p/571166#M161114</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-07-04T07:52:38Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting problem in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-problem-in-Proc-SQL/m-p/571174#M161115</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;&amp;nbsp;That is a nice, succinct but very useful table.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2019 08:26:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-problem-in-Proc-SQL/m-p/571174#M161115</guid>
      <dc:creator>koyelghosh</dc:creator>
      <dc:date>2019-07-04T08:26:51Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting problem in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-problem-in-Proc-SQL/m-p/571276#M161144</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi, I used the codes you provided and the log says insufficient space in WORK. Any further suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;73         proc sql;
74         	/*remove duplicates w/ the same enrolid, svcdate, and procgrp*/
75         	create table xing.outp_serv_noduprecs2 as
76         	select distinct enrolid, svcdate, procgrp
77         		from xing.outp_serv;
ERROR: Insufficient space in file WORK.'SASTMP-000000018'n.UTILITY.
ERROR: File WORK.'SASTMP-000000018'n.UTILITY is damaged. I/O processing did not complete.
NOTE: Error was encountered during utility-file processing. You may be able to execute the SQL statement successfully if you 
      allocate more space to the WORK library.

NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
78         		
79         	/*remove duplicates w/ the same enrolid and svcdate*/
80         	create table xing.outp_serv_noduprecs1 as
81         	select distinct enrolid, svcdate
82         		from xing.outp_serv;
NOTE: Statement not executed due to NOEXEC option.
83         quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Jul 2019 19:52:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-problem-in-Proc-SQL/m-p/571276#M161144</guid>
      <dc:creator>Xing</dc:creator>
      <dc:date>2019-07-04T19:52:56Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting problem in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-problem-in-Proc-SQL/m-p/571285#M161150</link>
      <description>&lt;P&gt;You have run out of space in your SAS WORK library. Assuming you are using a remote SAS server, talk to your SAS administrator regarding an increase in SAS WORK space.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2019 20:22:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-problem-in-Proc-SQL/m-p/571285#M161150</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-07-04T20:22:28Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting problem in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-problem-in-Proc-SQL/m-p/571297#M161154</link>
      <description>&lt;P&gt;Hash is not faster than proc sort for me, but uses less CPU (and much less memory).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data T1 ;                    
  if _n_ = 1 then do ;       
    dcl hash h (hashexp:20) ;
    h.definekey ("I", "J") ; 
    h.definedone () ;        
  end ;                      
  set T ;                    
  if h.check() ne 0 ;        
  h.add() ;                  
run ;  
 
data _null_ ;    
  call missing(I,J);               
  dcl hash h (dataset: 'T', hashexp:20, ordered:'a') ;
  h.definekey ("I", "J") ; 
  h.definedone () ;        
  h.output(dataset:'T1') ;                  
run ;    &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 11.23 seconds&lt;BR /&gt;user cpu time 8.84 seconds&lt;BR /&gt;system cpu time 1.56 seconds&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 9.50 seconds&lt;BR /&gt;user cpu time 7.75 seconds&lt;BR /&gt;system cpu time 1.25 seconds&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2019 23:29:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-problem-in-Proc-SQL/m-p/571297#M161154</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-07-04T23:29:49Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting problem in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-problem-in-Proc-SQL/m-p/571298#M161155</link>
      <description>&lt;P&gt;Use a hash table as shown, if the results suit your needs.&lt;/P&gt;
&lt;P&gt;The memory requirements are much much lower.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2019 23:31:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-problem-in-Proc-SQL/m-p/571298#M161155</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-07-04T23:31:35Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting problem in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-problem-in-Proc-SQL/m-p/571300#M161157</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/278143"&gt;@Xing&lt;/a&gt;&amp;nbsp;:&lt;/P&gt;
&lt;P&gt;First, I'd heed to advise given by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt; but would also urge you to clean up your work library before you resubmit the job just in case you have too much leftover junk there by running, for example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc delete data = work._all_ ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the job still fails and your admin isn't responsive enough to your needs, you'll have to get craftier, as many old-timers used to when trying to get more utility or sort DASD space was akin to starting a small war.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, the execution algorithm behind SQL is obviously I/O bound; hence you can try to move the burden to memory - provided, of course, that you have enough. In other words, you can try using a hash instead, e.g.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data xing.outp_serv_noduprecs2 ;                         
  if _n_ = 1 then do ;                              
    dcl hash h () ;                                 
    h.definekey  ("enrolid", "svcdate", "procgrp") ;
    h.definedata ("enrolid", "svcdate", "procgrp") ;
    h.definedone() ;                                
  end ;                                             
  set xing.outp_serv (keep = enrolid svcdate procgrp) ;       
  if h.check() ne 0 ;                               
  h.add() ;                                         
run ;                                               
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This code will preserve the original relative order of the input records. If you want the output ordered, run instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_ ;                                          
  if _n_ = 1 then do ;                                 
    dcl hash h (ordered:"A") ;                         
    h.definekey  ("enrolid", "svcdate", "procgrp") ;   
    h.definedata ("enrolid", "svcdate", "procgrp") ;   
    h.definedone() ;                                   
  end ;                                                
  set xing.outp_serv (keep = enrolid svcdate procgrp) end = z ;  
  h.ref() ;                                            
  if z then h.output (dataset:"xing.outp_serv_noduprecs2") ;
run ;                                                  
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;By the nature of the algorithm, memory usage for both variants above will be the same since in both, at the end the hash table contains all unique tuples of&amp;nbsp;(enrolid, svcdate, procgrp).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you discover that it works (i.e. you have more than enough memory for the task), then you can use the output to create the second file, xing.outp_serv_noduprecs1,&amp;nbsp;using either your second SQL query. Or, alternatively, you can use the hash object again, for instance:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_ ;                                                        
  if _n_ = 1 then do ;                                               
    dcl hash h (ordered:"A") ;                                       
    h.definekey  ("enrolid", "svcdate") ;                            
    h.definedata ("enrolid", "svcdate") ;                            
    h.definedone() ;                                                 
  end ;                                                              
  set xing.outp_serv_noduprecs2 (keep = enrolid svcdate procgrp) end = z ;
  h.ref() ;                                                          
  if z then h.output (dataset:"xing.outp_serv_noduprecs1") ;              
run ;                                                                
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In fact, if your SAS session is awash with RAM, so that it can hold both hash tables at once, both files can be created in a single pass through the input data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_ ;                                               
  dcl hash h1 (ordered:"A") ;                               
  h1.definekey  ("enrolid", "svcdate") ;                    
  h1.definedata ("enrolid", "svcdate") ;                    
  h1.definedone() ;                                         
  dcl hash h2 (ordered:"A") ;                               
  h2.definekey  ("enrolid", "svcdate", "procgrp") ;         
  h2.definedata ("enrolid", "svcdate", "procgrp") ;         
  h2.definedone() ;                                         
  do until (z) ;                                            
    set xing.outp_serv (keep = enrolid svcdate procgrp) end = z ;
    h1.ref() ;                                              
    h2.ref() ;                                              
  end ;                                                     
  h1.output (dataset:"xing.outp_serv_noduprecs1") ;              
  h2.output (dataset:"xing.outp_serv_noduprecs2") ;              
run ;                                                       
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Should all of the above still fail, you'd have to get still craftier and split your input into N key-independent subgroups, sacrificing some efficiency by making N passes through the input data. However, it virtually guarantees that if N is high enough, your job will eventually succeed. Since it's a topic a bit too voluminous for a reply to a question here, I'd merely suggest that you read this paper:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2018/1755-2018.pdf" target="_blank" rel="noopener"&gt;https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2018/1755-2018.pdf&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jul 2019 00:05:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-problem-in-Proc-SQL/m-p/571300#M161157</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-07-05T00:05:07Z</dc:date>
    </item>
  </channel>
</rss>

