<?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: SQL To Delete Observations by Key and Date Range in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/SQL-To-Delete-Observations-by-Key-and-Date-Range/m-p/57857#M16139</link>
    <description>Sorry, double post.

Message was edited by: Superman</description>
    <pubDate>Thu, 23 Jul 2009 17:03:27 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-07-23T17:03:27Z</dc:date>
    <item>
      <title>SQL To Delete Observations by Key and Date Range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-To-Delete-Observations-by-Key-and-Date-Range/m-p/57856#M16138</link>
      <description>I have two different SAS datasets setup like the following...&lt;BR /&gt;
&lt;BR /&gt;
Dataset1&lt;BR /&gt;
ID Date&lt;BR /&gt;
1 31/01/2009&lt;BR /&gt;
1 28/02/2009&lt;BR /&gt;
1 30/03/2009&lt;BR /&gt;
...&lt;BR /&gt;
&lt;BR /&gt;
Dataset2&lt;BR /&gt;
1 StartDate EndDate&lt;BR /&gt;
1 28/02/2009   29/03/2009&lt;BR /&gt;
&lt;BR /&gt;
I wish to delete from dataset1 where StartDate (LE) date (LE) EndDate to leave the following&lt;BR /&gt;
&lt;BR /&gt;
Dataset1&lt;BR /&gt;
1 31/01/2009&lt;BR /&gt;
1 30/03/2009&lt;BR /&gt;
...&lt;BR /&gt;
&lt;BR /&gt;
I've managed to come up with something that worked....&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table dataset1 as&lt;BR /&gt;
select	a.*&lt;BR /&gt;
from dataset1 as a&lt;BR /&gt;
left join&lt;BR /&gt;
dataset2 as b&lt;BR /&gt;
on a.id=b.id and (b.startdate LE a.date LE b.enddate)&lt;BR /&gt;
having missing(b.id)&lt;BR /&gt;
order by a.id, a.date&lt;BR /&gt;
;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
However, I was wondering if there was something that I could do in a "DELETE FROM" way?&lt;BR /&gt;
&lt;BR /&gt;
I noticed that SQL could use the "DELETE FROM... USING" but couldn't get it to work.&lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance.&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: Superman

Message was edited by: Superman</description>
      <pubDate>Thu, 23 Jul 2009 17:00:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-To-Delete-Observations-by-Key-and-Date-Range/m-p/57856#M16138</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-07-23T17:00:29Z</dc:date>
    </item>
    <item>
      <title>Re: SQL To Delete Observations by Key and Date Range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-To-Delete-Observations-by-Key-and-Date-Range/m-p/57857#M16139</link>
      <description>Sorry, double post.

Message was edited by: Superman</description>
      <pubDate>Thu, 23 Jul 2009 17:03:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-To-Delete-Observations-by-Key-and-Date-Range/m-p/57857#M16139</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-07-23T17:03:27Z</dc:date>
    </item>
  </channel>
</rss>

