<?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: Deleteteing data in SAS between 2 dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Deleteteing-data-in-SAS-between-2-dates/m-p/357114#M83810</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Always post test data in the form of a datastep, this avoids us guessing what it looks like. &amp;nbsp;I assume than FDATE is a numeric SAS date here. &amp;nbsp;Also be aware there is no reverse of this procedure, be very sure that you a) want to delete from the dataset, b) know what you are deleting. &amp;nbsp;Again, I want you to be fully aware that this removes the data from the table in place - doesn't create a new dataset, deletes from that one - be very sure this is what you want to do!!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
  delete from &amp;lt;your_dataset&amp;gt; 
  where FDATE between '01JAN2009'd and '31DEC2010'd;
quit;&lt;/PRE&gt;</description>
    <pubDate>Tue, 09 May 2017 10:04:32 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-05-09T10:04:32Z</dc:date>
    <item>
      <title>Deleteteing data in SAS between 2 dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleteteing-data-in-SAS-between-2-dates/m-p/357112#M83809</link>
      <description>&lt;P&gt;Hi, I have about 18 million rows of data and a lot of the data is pretty old and it goes back to 2009. One of the columns is a date field called fdate&amp;nbsp;and the format is 01/01/2017 it is also in text, I would like to delete all records that have a date between 01/01/2009 and 31/12/2010. What is the best way to do this? I have included below an example of the data in question, the data included below is only test data. Your help in this matter would be much appreciated&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using SAS EG 7.1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;mpr&lt;/TD&gt;&lt;TD&gt;ReadDate&lt;/TD&gt;&lt;TD&gt;Source&lt;/TD&gt;&lt;TD&gt;reason&lt;/TD&gt;&lt;TD&gt;rej1&lt;/TD&gt;&lt;TD&gt;rej2&lt;/TD&gt;&lt;TD&gt;rej3&lt;/TD&gt;&lt;TD&gt;rej4&lt;/TD&gt;&lt;TD&gt;fname&lt;/TD&gt;&lt;TD&gt;fdate&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;20101210&lt;/TD&gt;&lt;TD&gt;E&lt;/TD&gt;&lt;TD&gt;N&lt;/TD&gt;&lt;TD&gt;aaa&lt;/TD&gt;&lt;TD&gt;bbb&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;ABC&lt;/TD&gt;&lt;TD&gt;13/12/2010&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Tue, 09 May 2017 09:54:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleteteing-data-in-SAS-between-2-dates/m-p/357112#M83809</guid>
      <dc:creator>zdassu</dc:creator>
      <dc:date>2017-05-09T09:54:58Z</dc:date>
    </item>
    <item>
      <title>Re: Deleteteing data in SAS between 2 dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleteteing-data-in-SAS-between-2-dates/m-p/357114#M83810</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Always post test data in the form of a datastep, this avoids us guessing what it looks like. &amp;nbsp;I assume than FDATE is a numeric SAS date here. &amp;nbsp;Also be aware there is no reverse of this procedure, be very sure that you a) want to delete from the dataset, b) know what you are deleting. &amp;nbsp;Again, I want you to be fully aware that this removes the data from the table in place - doesn't create a new dataset, deletes from that one - be very sure this is what you want to do!!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
  delete from &amp;lt;your_dataset&amp;gt; 
  where FDATE between '01JAN2009'd and '31DEC2010'd;
quit;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 May 2017 10:04:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleteteing-data-in-SAS-between-2-dates/m-p/357114#M83810</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-05-09T10:04:32Z</dc:date>
    </item>
    <item>
      <title>Re: Deleteteing data in SAS between 2 dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleteteing-data-in-SAS-between-2-dates/m-p/357115#M83811</link>
      <description>&lt;P&gt;Maxim 33: Intelligent data makes for intelligent programs!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Convert your text date variables to real SAS date variables, and the comparison will be a breeze:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
where &amp;amp;start &amp;lt;= fdate &amp;lt;= &amp;amp;end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;where &amp;amp;start and &amp;amp;end could contain SAS date literals or raw numerical values that correspond to the wanted cutoff dates.&lt;/P&gt;
&lt;P&gt;The conversion would go like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
set have (rename=(fdate=_fdate));
fdate = input(_fdate,ddmmyy10.);
format fdate ddmmyy10.;
drop _fdate;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 May 2017 10:06:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleteteing-data-in-SAS-between-2-dates/m-p/357115#M83811</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-05-09T10:06:13Z</dc:date>
    </item>
    <item>
      <title>Re: Deleteteing data in SAS between 2 dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleteteing-data-in-SAS-between-2-dates/m-p/357119#M83812</link>
      <description>&lt;P&gt;Hi Kurtbremser&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your help, I have converted the text date to date format but I think there is something wrong with my code as the results are coming back with no data. please see my code below.&lt;/P&gt;&lt;PRE&gt;&lt;BR /&gt;data want;
set have;
where 01/01/2009 &amp;lt;= fdate &amp;lt;= 31/12/2010;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 May 2017 11:06:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleteteing-data-in-SAS-between-2-dates/m-p/357119#M83812</guid>
      <dc:creator>zdassu</dc:creator>
      <dc:date>2017-05-09T11:06:30Z</dc:date>
    </item>
    <item>
      <title>Re: Deleteteing data in SAS between 2 dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleteteing-data-in-SAS-between-2-dates/m-p/357121#M83814</link>
      <description>&lt;P&gt;apply date constant "datemonthyear"d&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2017 11:10:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleteteing-data-in-SAS-between-2-dates/m-p/357121#M83814</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-05-09T11:10:02Z</dc:date>
    </item>
    <item>
      <title>Re: Deleteteing data in SAS between 2 dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleteteing-data-in-SAS-between-2-dates/m-p/357124#M83816</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/59173"&gt;@zdassu&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi Kurtbremser&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your help, I have converted the text date to date format but I think there is something wrong with my code as the results are coming back with no data. please see my code below.&lt;/P&gt;
&lt;PRE&gt;&lt;BR /&gt;data want;
set have;
where 01/01/2009 &amp;lt;= fdate &amp;lt;= 31/12/2010;
run;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Oh, young Padawan, you need to study the secrets of SAS date and time values, before you can embark on the journey to mastership!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I specifically recommend &lt;A href="https://support.sas.com/resources/papers/proceedings15/1334-2015.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings15/1334-2015.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In short, to specify a date literal, you need to follow the structure "ddmmmyyyy"d, so your dates would be spelled as&lt;/P&gt;
&lt;P&gt;"01jan2009"d and "31dec2010"d, respectively.&lt;/P&gt;
&lt;P&gt;Note that dates are actually a simple number, counting the days from 01jan1960, in both directions (positive and negative).&lt;/P&gt;
&lt;P&gt;Therefore, you could also use this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
start = mdy(1,1,2009);
call symputx('start_date',put(start,best.));
end = mdy(12,31,2010);
call symputx('end_date',put(end,best.));
run;

data want;
set have;
where &amp;amp;start_date &amp;lt;= fdate &amp;lt;= &amp;amp;end_date;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you also insert %put &amp;amp;start_date; somewhere in the code and look at the log, you will find that it contains the raw value, but just works as well.&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2017 11:17:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleteteing-data-in-SAS-between-2-dates/m-p/357124#M83816</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-05-09T11:17:53Z</dc:date>
    </item>
    <item>
      <title>Re: Deleteteing data in SAS between 2 dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleteteing-data-in-SAS-between-2-dates/m-p/357151#M83825</link>
      <description>&lt;P&gt;Hi kurt&lt;/P&gt;&lt;P&gt;I tried the code but I am getting an error in the log&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: Syntax error while parsing WHERE clause.&lt;/P&gt;&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;FONT face="Courier New" size="3"&gt;data want;
set have;
where &amp;amp;"01jan2009"d &amp;lt;= fdate &amp;lt;= &amp;amp;"31dec2010"d;
run;&lt;/FONT&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 May 2017 12:19:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleteteing-data-in-SAS-between-2-dates/m-p/357151#M83825</guid>
      <dc:creator>zdassu</dc:creator>
      <dc:date>2017-05-09T12:19:13Z</dc:date>
    </item>
    <item>
      <title>Re: Deleteteing data in SAS between 2 dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleteteing-data-in-SAS-between-2-dates/m-p/357154#M83826</link>
      <description>&lt;P&gt;&amp;amp; is a macro trigger, it has to be followed by a macro variable name, not by a value or literal. If you want to use macro variables, use my code AS IS.&lt;/P&gt;
&lt;P&gt;If not, use the date literals without any additional characters.&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2017 12:27:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleteteing-data-in-SAS-between-2-dates/m-p/357154#M83826</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-05-09T12:27:06Z</dc:date>
    </item>
    <item>
      <title>Re: Deleteteing data in SAS between 2 dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleteteing-data-in-SAS-between-2-dates/m-p/357167#M83828</link>
      <description>Thanks Kurt&lt;BR /&gt;I think I was getting a little confused, I was inserting the dates I didn't want to keep in the code, once I entered the dates I wanted to keep and ran the whole code together it worked. Thanks for all your help much appreciated</description>
      <pubDate>Tue, 09 May 2017 13:08:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleteteing-data-in-SAS-between-2-dates/m-p/357167#M83828</guid>
      <dc:creator>zdassu</dc:creator>
      <dc:date>2017-05-09T13:08:26Z</dc:date>
    </item>
  </channel>
</rss>

