<?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 subset a very large dataset by date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-subset-a-very-large-dataset-by-date/m-p/602305#M174357</link>
    <description>&lt;P&gt;&lt;EM&gt;"But this is taking a long time and sometime crashes, not to mention putting a datetime format on the original&amp;nbsp;&lt;STRONG&gt;date&lt;/STRONG&gt;&amp;nbsp;variable were even slower or nearly impossible."&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Given how simple your where clause is I'm asking myself if the real problem isn't just reading this source table at all. How big is it actually in GB? And are you reading the data over a slow or unstable network connection?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For subsetting using the string: Why not also use the year? I'd expect this to perform better than using a substr() first.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have(where=(date like '2018-04-03%'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Eventually try and use Proc Append.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc datasets lib=work nolist nowarn;
  delete want;
  run;
  append base=want data=have(where=(date like '2018-04-03%'));
  run;
quit;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 07 Nov 2019 03:42:49 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2019-11-07T03:42:49Z</dc:date>
    <item>
      <title>How to subset a very large dataset by date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-subset-a-very-large-dataset-by-date/m-p/602297#M174353</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;Frequently&amp;nbsp; I find that the limited memory is preventing Hash to run, but the data can still be processed through proc sort.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a very large dataset, and I'm trying to reduce its size by the date of when the data is imported. The &lt;STRONG&gt;date&lt;/STRONG&gt; variable is in string format such as the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2018-04-03 06:40:28.738&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will need to subset the dataset by date, if the size of the dataset were smaller, I will only need to use the where statement such as:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;where trim(substr(date,7,4)) = "4-03";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But this is taking a long time and sometime crashes, not to mention putting a datetime format on the original &lt;STRONG&gt;date&lt;/STRONG&gt; variable were even slower or nearly impossible. Create a new variable with only date on the raw dataset was also pretty impossible.(If I could do that easily then I would not need to subset by date)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can create a hash table and a hash dataset that contains the &lt;STRONG&gt;date&lt;/STRONG&gt;, but the original &lt;STRONG&gt;date&lt;/STRONG&gt; variable has date + time. Therefore, it will not match.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Following is a sample dataset with only date:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input date $30;
  cards;
2018-04-03 03:44:18.728
2018-04-03 07:40:02.221
2018-04-03 09:20:20.135
2018-04-03 14:50:11.752
2018-04-03 02:42:17.005
2018-04-05 01:22:20.264
2018-04-05 04:45:49.402
2018-04-06 04:09:50.710
2018-04-07 04:12:31.623
2018-04-11 04:11:01.528

;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have already tried to reduce variables, but it did not help much since the data is very long as well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Appreciate for any help!&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2019 03:11:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-subset-a-very-large-dataset-by-date/m-p/602297#M174353</guid>
      <dc:creator>lydiawawa</dc:creator>
      <dc:date>2019-11-07T03:11:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to subset a very large dataset by date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-subset-a-very-large-dataset-by-date/m-p/602302#M174355</link>
      <description>&lt;P&gt;Part of the reason your WHERE filter is taking so long is that you are looking at a substring within a string variable, as in&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; where trim(substr(date,7,4)) = "4-03"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You would be better off converting your string into numeric variables, namely:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;a DATE variable, call it MYDATE&lt;/LI&gt;
&lt;LI&gt;a TIME variable, call it MYTiME&lt;/LI&gt;
&lt;LI&gt;and possibly a datetime variable&amp;nbsp; (MYDATETIME)..&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Then your&amp;nbsp;where filter can be a straight equality&lt;/P&gt;
&lt;P&gt;&amp;nbsp; where mydate='03apr2018'd;&lt;/P&gt;
&lt;P&gt;which is likely to be much faster.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or&amp;nbsp;if you want April 3 for many years, you could use&lt;/P&gt;
&lt;P&gt;&amp;nbsp; where mydate in ('03apr2018'd,'03apr2019'd,.....);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's how to create such variables:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input mydate yymmdd10.  mytime time12.3;
  format mydate date9.  mytime time12.3;
  cards;
2018-04-03 03:44:18.728
2018-04-03 07:40:02.221
2018-04-03 09:20:20.135
2018-04-03 14:50:11.752
2018-04-03 02:42:17.005
2018-04-05 01:22:20.264
2018-04-05 04:45:49.402
2018-04-06 04:09:50.710
2018-04-07 04:12:31.623
2018-04-11 04:11:01.528
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So I would consider making variables more friendly to where-filters before you choose to break up the data set.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In addition, you could create an index on the variable, which would likely further&amp;nbsp;speed up where-filter performance.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2019 03:20:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-subset-a-very-large-dataset-by-date/m-p/602302#M174355</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-11-07T03:20:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to subset a very large dataset by date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-subset-a-very-large-dataset-by-date/m-p/602303#M174356</link>
      <description>&lt;P&gt;If you are just sub-setting a dataset on disk then I don't think using a hash table will help because all the data has to be read off disk anyway first to see if it satisfies your selection criteria and that is the slowest part of any processing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What do you want to do with the data once it is subset? This is probably the key to deciding what processing technique to use. If you want it sorted and / or deduped or some other DATA step processing then hash could be useful.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2019 03:27:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-subset-a-very-large-dataset-by-date/m-p/602303#M174356</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-11-07T03:27:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to subset a very large dataset by date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-subset-a-very-large-dataset-by-date/m-p/602305#M174357</link>
      <description>&lt;P&gt;&lt;EM&gt;"But this is taking a long time and sometime crashes, not to mention putting a datetime format on the original&amp;nbsp;&lt;STRONG&gt;date&lt;/STRONG&gt;&amp;nbsp;variable were even slower or nearly impossible."&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Given how simple your where clause is I'm asking myself if the real problem isn't just reading this source table at all. How big is it actually in GB? And are you reading the data over a slow or unstable network connection?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For subsetting using the string: Why not also use the year? I'd expect this to perform better than using a substr() first.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have(where=(date like '2018-04-03%'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Eventually try and use Proc Append.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc datasets lib=work nolist nowarn;
  delete want;
  run;
  append base=want data=have(where=(date like '2018-04-03%'));
  run;
quit;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2019 03:42:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-subset-a-very-large-dataset-by-date/m-p/602305#M174357</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-11-07T03:42:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to subset a very large dataset by date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-subset-a-very-large-dataset-by-date/m-p/602318#M174365</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30435"&gt;@lydiawawa&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;What you are asking to do is easy by assigning an appropriate expression to the KEY argument tag when the CHECK method is called, for example:&lt;/P&gt;
&lt;PRE&gt;data have ;                                                                                                                             
  input @1 date $23. x y :$1. z :$3. ;                                                                                                  
  cards ;                                                                                                                               
2018-04-03 03:44:18.728   1  A  A01                                                                                                     
2018-04-03 07:40:02.221   2  B  B02                                                                                                     
2018-05-03 09:20:20.135   3  C  C03                                                                                                     
2018-06-03 14:50:11.752   4  D  D04                                                                                                     
2018-07-03 02:42:17.005   5  E  E05                                                                                                     
2018-08-05 01:22:20.264   6  F  F06                                                                                                     
2018-01-06 04:45:49.402   7  G  G07                                                                                                     
2018-11-06 04:09:50.710   8  H  H08                                                                                                     
2018-07-07 04:12:31.623   9  I  I09                                                                                                     
2018-12-11 04:11:01.528  10  J  J10                                                                                                     
;                                                                                                                                       
run ;                                                                                                                                   
                                                                                                                                        
data dates ;                                                                                                                            
  input m_yy $4. ;                                                                                                                      
  cards ;                                                                                                                               
4-03                                                                                                                                    
1-06                                                                                                                                    
;                                                                                                                                       
run ;                                                                                                                                   
                                                                                                                                        
data want (drop = m_yy) ;                                                                                                               
  if _n_ = 1 then do ;                                                                                                                  
    if 0 then set dates ;                                                                                                               
    dcl hash h (dataset: "dates") ;                                                                                                     
    h.definekey ("m_yy") ;                                                                                                              
    h.definedone () ;                                                                                                                   
  end ;                                                                                                                                 
  set have ;                                                                                                                            
  if h.check (&lt;FONT color="#0000FF"&gt;key: put (substr (date, 7), $4.)&lt;/FONT&gt;) = 0 ;                                                                                   
run ;                                       
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;However, from what you've said I suspect it's not the real snag. If you run into a problem just applying a WHERE clause to the input, hash code akin to the above isn't going to help you much. Most likely, in your input you have a "tail" of satellite variables, much more numerous than X Y Z I've included for the sake of a demo; and though WHERE moves only the records that qualify from the buffer to the PDV, it fails to relieve the I/O burden created by the satellites enough. With the hash code like above, the things are even worse because every record gets moved from the buffer into the PDV before the unwanted ones get discarded by the subsetting IF.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hence, the strategy needs to be adjusted depending on the nature of your input data. Just to outline two extreme scenarios, suppose that the records you end up selecting constitute:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;but a fraction of the whole input or&lt;/LI&gt;
&lt;LI&gt;a lion's share of the input&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;In both cases, you have very few records to either (1) filter in or (2) filter out. And in both cases, it makes sense to first identify those records by observation number with as little computer resource pain as possible and (1) employ some tactic to get those you need or (2) mark those you don't want as deleted. Either way, at this stage it makes sense to drop all the satellite variables, reading in only the key, and apply the subsetting criteria to it, so that in the end you end up with a list of record IDs (i.e. the observation numbers) you either (1) want or (2) don't want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's first look at #1:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop = m_yy) ;                                                                                                               
* hash to lookup m_yy ;                                                                                                                 
  dcl hash h (dataset: "dates") ;                                                                                                       
  h.definekey ("m_yy") ;                                                                                                                
  h.definedone () ;                                                                                                                     
  dcl hash r () ;                                                                                                                       
* hash to store filtered-in RIDs ;                                                                                                      
  r.definekey ("rid") ;                                                                                                                 
  r.definedone () ;                                                                                                                     
  dcl hiter ir ("r") ;                                                                                                                  
* find needed RIDs ;                                                                                                                    
  do rid = 1 by 1 until (lr) ;                                                                                                          
  * KEEP is critical in SET below ;                                                                                                     
    set have (keep = date) end = lr ;                                                                                                   
    if h.check (key: put (substr (date, 7), $4.)) = 0 then r.add() ;                                                                    
  end ;                                                                                                                                 
* select only records with RIDs in hash R from HAVE ;                                                                                   
  do while (ir.next() = 0) ;                                                                                                            
    set have point = rid ;                                                                                                              
    output ;                                                                                                                            
  end ;                                                                                                                                 
  stop ;                                                                                                                                
  set dates ;                                                                                                                           
run ;             
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In the extreme scenario #2, you &lt;EM&gt;don't want&lt;/EM&gt; any record with M_YY in file DATES:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data discard (keep = rid) ;                                                                                                             
  if _n_ = 1 then do ;                                                                                                                  
    if 0 the set dates ;                                                                                                                
    dcl hash h (dataset: "dates") ;                                                                                                     
    h.definekey ("m_yy") ;                                                                                                              
    h.definedone () ;                                                                                                                   
  end ;                                                                                                                                 
* KEEP is critical in SET below ;                                                                                                       
  set have (keep = date) ;                                                                                                              
* find UNneeded RIDs ;                                                                                                                  
  if h.check (key: put (substr (date, 7), $4.)) = 0 ;                                                                                   
  rid = _n_ ;                                                                                                                           
run ;                                                                                                                                   
                                                                                                                                        
data have ;                                                                                                                             
  set discard ;                                                                                                                         
  modify have point = rid ;                                                                                                             
  remove ;                                                                                                                              
run ;                   
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In this case, you just make a list of the &lt;EM&gt;unwanted&lt;/EM&gt; RIDs in the first step (which reads nothing but the key) and in the second step, use that list to mark the respective records in the data set HAVE itself as "deleted". In this case, you (a) still have never read anything from HAVE except the key, (b) never written out a huge data set with all the satellites and only a few records discarded. You've merely marked the unwanted records as "deleted" in HAVE. So, in your program downstream you will just read the data set HAVE; and all the records marked for deletion will be automatically ignored.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course, there're other scenarios in between these two extremes. But you should be getting the drift. When you deal with voluminous data, it's not always clearly cut and one has to be inventive; it's an art as much as a science. At times, to engineer a successful ETL, one needs to do a distribution analysis on the keys only first and then write a dynamic program smart enough to choose a subsetting tactic based on the distribution.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2019 05:10:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-subset-a-very-large-dataset-by-date/m-p/602318#M174365</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-11-07T05:10:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to subset a very large dataset by date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-subset-a-very-large-dataset-by-date/m-p/602323#M174367</link>
      <description>&lt;P&gt;Though the file is huge, try:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data small;
 set have(keep=date);
     seq = _N_;
     keep seq date;
run;

data obs2keep(kee=seq);
  set small;
      if substr(date, .......);
run;

data want(drop=seq);
 merge obs2keep have;
   by;
      if seq;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Nov 2019 06:00:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-subset-a-very-large-dataset-by-date/m-p/602323#M174367</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2019-11-07T06:00:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to subset a very large dataset by date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-subset-a-very-large-dataset-by-date/m-p/602326#M174369</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;This way, in the final step you still have to read HAVE in its entirety with all its variables, while the OP says this is what causes the job to either run forever or crash.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2019 06:18:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-subset-a-very-large-dataset-by-date/m-p/602326#M174369</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-11-07T06:18:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to subset a very large dataset by date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-subset-a-very-large-dataset-by-date/m-p/602328#M174370</link>
      <description>&lt;P&gt;Start by reducing your dataset size considerably by converting the overlong string to a datetime, or date and time variable(s). A date can be reduced to a length of 4, equally a time (if you do not have fractions of a second!); datetimes can be stored in one 8-byte number (with precision down to microseconds!).&lt;/P&gt;
&lt;P&gt;Since proc sort still works, creating an index on your variables will also work.&lt;/P&gt;
&lt;P&gt;If you need to subset for specific days in a year, create a new month/day string from your date (will only need 4 bytes also) and create an index on that. Indexes work well when you use them to retrieve a small subset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If a where condition crashes, you have other problems (where processes each observation individually, so it does not need more memory than one observation size). You either run out of space writing the subset, or you run into problems reading the input caused by a bad storage setup (network share, unreliable connections). Always keep the datasets you work with on local disks or disks attached through a reliable SAN.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What are the symptoms of your crashes? Please supply the respective log.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2019 06:31:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-subset-a-very-large-dataset-by-date/m-p/602328#M174370</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-11-07T06:31:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to subset a very large dataset by date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-subset-a-very-large-dataset-by-date/m-p/602356#M174389</link>
      <description>&lt;P&gt;I would like to quote few sentences:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30435"&gt;@lydiawawa&lt;/a&gt;&amp;nbsp;wrote:&lt;/P&gt;
&lt;PRE&gt;But this is taking a long time and sometime crashes, not to mention &lt;BR /&gt;putting a datetime format on the original date variable were even slower or nearly impossible.&lt;BR /&gt;Create a new variable with only date on the raw dataset was also pretty impossible.&lt;BR /&gt;(If I could do that easily then I would not need to subset by date)&lt;/PRE&gt;
&lt;P&gt;and&lt;/P&gt;
&lt;PRE&gt; I find that the limited memory is preventing Hash to run, but the data can still be processed through proc sort.&lt;/PRE&gt;
&lt;P&gt;If sort can be done, I understand:&lt;/P&gt;
&lt;P&gt;1) No problem to read the whole file&lt;/P&gt;
&lt;P&gt;2) There is enough space to hold a small file&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;&amp;nbsp;, according to above, my suggested code reads the huge file twice,&lt;/P&gt;
&lt;P&gt;I believe it can run fast enough without crashing.&lt;/P&gt;
&lt;P&gt;It seems to me that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;is right about possible reasons to a crash.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Worth to try.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2019 11:09:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-subset-a-very-large-dataset-by-date/m-p/602356#M174389</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2019-11-07T11:09:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to subset a very large dataset by date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-subset-a-very-large-dataset-by-date/m-p/602376#M174403</link>
      <description>The crash is caused by usually the prior: "run out of space writing the subset", and it depends on how many people are running the program at once. Currently, it is not crashing but the average run time of subsetting dataset (through where indexing) by date is around 9 to 10 mins..&lt;BR /&gt;&lt;BR /&gt;"create a new month/day string" : creating a new variable requires formatting and it seems the time to create and indexing is the same amount as comparing to just index on the original variable.</description>
      <pubDate>Thu, 07 Nov 2019 13:32:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-subset-a-very-large-dataset-by-date/m-p/602376#M174403</guid>
      <dc:creator>lydiawawa</dc:creator>
      <dc:date>2019-11-07T13:32:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to subset a very large dataset by date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-subset-a-very-large-dataset-by-date/m-p/602379#M174406</link>
      <description>will the delete in proc datasets delete the original file? I'm extracting a file that is saved as a permanent file because work folder may not have enough space. I cannot delete the original file.</description>
      <pubDate>Thu, 07 Nov 2019 13:37:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-subset-a-very-large-dataset-by-date/m-p/602379#M174406</guid>
      <dc:creator>lydiawawa</dc:creator>
      <dc:date>2019-11-07T13:37:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to subset a very large dataset by date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-subset-a-very-large-dataset-by-date/m-p/602384#M174410</link>
      <description>How should I apply the format on a dataset to split the time variable? The 'input' in my case will be 'set'. I will have more than one variable, how would format know which one to apply the date format?</description>
      <pubDate>Thu, 07 Nov 2019 13:54:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-subset-a-very-large-dataset-by-date/m-p/602384#M174410</guid>
      <dc:creator>lydiawawa</dc:creator>
      <dc:date>2019-11-07T13:54:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to subset a very large dataset by date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-subset-a-very-large-dataset-by-date/m-p/602390#M174414</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30435"&gt;@lydiawawa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;The crash is caused by usually the prior: "run out of space writing the subset", and it depends on how many people are running the program at once. Currently, it is not crashing but the average run time of subsetting dataset (through where indexing) by date is around 9 to 10 mins..&lt;BR /&gt;&lt;BR /&gt;"create a new month/day string" : creating a new variable requires formatting and it seems the time to create and indexing is the same amount as comparing to just index on the original variable.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;How big is your dataset, anyway? Either give us the filesize in GB, or the number of observations and the observation size.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Creating a new variable that speeds up an operation is a one-time process upfront; since you seem to run the subset repeatedly, performance gained will outweigh the effort spent in the long run. But first we need to know your situation in depth.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I just ran a test with a fake dataset:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
format date yymmddd10.;
string = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; * add some meat;
do i = 1 to 10000000;
  date = rand('integer','01jan1960'd,today());
  datestring = put(date,yymmddd10.);
  md = cats(put(month(date),z2.),put(day(date),z2.));
  output;
end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and created a subset twice:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want1;
set have;
where substr(datestring,7,4) = '4-03';
run;

data want2;
set have;
where md = '0403';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The difference between the two data steps was 32 to 39 seconds, so not that big, and could be caused by simultaneous loads on the server.&lt;/P&gt;
&lt;P&gt;Then I created indexes:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc datasets library=work;
modify have;
index create datestring;
index create md;
run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and reran the two subsets, and found no real difference to before (both runs now ~35 seconds). If the probability of a certain value appearing in any given dataset page is high, the index will not speed up the process, and often slow it down. Only when the index prevents reading a substantial amount of dataset pages will it really help.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2019 14:02:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-subset-a-very-large-dataset-by-date/m-p/602390#M174414</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-11-07T14:02:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to subset a very large dataset by date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-subset-a-very-large-dataset-by-date/m-p/602575#M174470</link>
      <description>&lt;P&gt;The dataset size is about 407833 million bytes. Page size: 65536&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2019 20:04:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-subset-a-very-large-dataset-by-date/m-p/602575#M174470</guid>
      <dc:creator>lydiawawa</dc:creator>
      <dc:date>2019-11-07T20:04:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to subset a very large dataset by date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-subset-a-very-large-dataset-by-date/m-p/602588#M174476</link>
      <description>&lt;P&gt;400 Gigabytes? Then the 10 minutes are in fact very fast, as you read 1GB in 1.5 seconds.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30435"&gt;@lydiawawa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;The dataset size is about 407833 million bytes. Page size: 65536&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2019 20:20:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-subset-a-very-large-dataset-by-date/m-p/602588#M174476</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-11-07T20:20:39Z</dc:date>
    </item>
  </channel>
</rss>

