<?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: Restriction of data based on dates. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Restriction-of-data-based-on-dates/m-p/455117#M115099</link>
    <description>&lt;P&gt;You can see that, with your original example data, my code eliminated exactly the row you wanted eliminated, and kept the 4 others.&lt;/P&gt;
&lt;P&gt;For code tested with certain data, you need to supply that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may need to add&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   and
   b.Record_id = a.Record_id
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;in the where condition of the subquery.&lt;/P&gt;</description>
    <pubDate>Wed, 18 Apr 2018 11:57:00 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-04-18T11:57:00Z</dc:date>
    <item>
      <title>Restriction of data based on dates.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Restriction-of-data-based-on-dates/m-p/454719#M114929</link>
      <description>&lt;P&gt;Dear SAS Experts&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have what I think is a simple problem that I hope you can help me with.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following data and would like to exclude line number 3 and keep number 2. Please notice that it is the date of diagnosis that are of interest and in both cases these are after admission but in line 3 it is after admission&amp;nbsp;and within the time frame of the 2 admission.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Record_id&lt;/TD&gt;&lt;TD&gt;admission_number&lt;/TD&gt;&lt;TD&gt;Admission date&lt;/TD&gt;&lt;TD&gt;Discharge date&lt;/TD&gt;&lt;TD&gt;date of diagnosis&lt;/TD&gt;&lt;TD&gt;diagnosis&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;01-01-2010&lt;/TD&gt;&lt;TD&gt;01-02-2010&lt;/TD&gt;&lt;TD&gt;02-01-2010&lt;/TD&gt;&lt;TD&gt;df200&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;01-01-2010&lt;/TD&gt;&lt;TD&gt;01-02-2010&lt;/TD&gt;&lt;TD&gt;02-03-2010&lt;/TD&gt;&lt;TD&gt;df100&lt;/TD&gt;&lt;TD&gt;I want to keep this line&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;01-01-2010&lt;/TD&gt;&lt;TD&gt;01-02-2010&lt;/TD&gt;&lt;TD&gt;04-03-2010&lt;/TD&gt;&lt;TD&gt;df147&lt;/TD&gt;&lt;TD&gt;I want to exclude this line&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;03-03-2010&lt;/TD&gt;&lt;TD&gt;31-03-2010&lt;/TD&gt;&lt;TD&gt;04-03-2010&lt;/TD&gt;&lt;TD&gt;df147&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;03-03-2010&lt;/TD&gt;&lt;TD&gt;31-03-2010&lt;/TD&gt;&lt;TD&gt;04-03-2010&lt;/TD&gt;&lt;TD&gt;df200&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Solvej&lt;/P&gt;</description>
      <pubDate>Tue, 17 Apr 2018 12:46:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Restriction-of-data-based-on-dates/m-p/454719#M114929</guid>
      <dc:creator>Solvej</dc:creator>
      <dc:date>2018-04-17T12:46:33Z</dc:date>
    </item>
    <item>
      <title>Re: Restriction of data based on dates.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Restriction-of-data-based-on-dates/m-p/454724#M114931</link>
      <description>&lt;P&gt;Please supply example data in a usable form, see my footnotes.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Apr 2018 12:57:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Restriction-of-data-based-on-dates/m-p/454724#M114931</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-04-17T12:57:08Z</dc:date>
    </item>
    <item>
      <title>Re: Restriction of data based on dates.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Restriction-of-data-based-on-dates/m-p/455056#M115066</link>
      <description>&lt;P&gt;Dear KurtBremser&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I apologize for the data. I have very sensitive data so I have to make everything up for my questions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this datastep is useful. The date formats are not correct, but Im unable to find the correct ones. My you know what will work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; have;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; Record_id admission_number Admission_date &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;DATE10.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; Discharge_date &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;date10.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; date_of_diagnosis &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;date10.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; diagnosis $;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;format&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; Admission_date &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;date10.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; Discharge_date &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;date10.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; date_of_diagnosis &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;date10.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 1 01-01-2010 01-02-2010 02-01-2010 df200&lt;/P&gt;&lt;P&gt;1 1 01-01-2010 01-02-2010 02-03-2010 df100&lt;/P&gt;&lt;P&gt;1 1 01-01-2010 01-02-2010 04-03-2010 df147&lt;/P&gt;&lt;P&gt;1 2 03-03-2010 31-03-2010 04-03-2010 df147&lt;/P&gt;&lt;P&gt;1 2 03-03-2010 31-03-2010 04-03-2010 df200&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;run&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Solvej&lt;/P&gt;</description>
      <pubDate>Wed, 18 Apr 2018 07:40:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Restriction-of-data-based-on-dates/m-p/455056#M115066</guid>
      <dc:creator>Solvej</dc:creator>
      <dc:date>2018-04-18T07:40:13Z</dc:date>
    </item>
    <item>
      <title>Re: Restriction of data based on dates.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Restriction-of-data-based-on-dates/m-p/455064#M115070</link>
      <description>&lt;P&gt;It takes some kind of SQL trickery:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input
  Record_id
  admission_number
  (Admission_date Discharge_date date_of_diagnosis) (:ddmmyy10.)
  diagnosis $
;
format Admission_date Discharge_date date_of_diagnosis ddmmyyd10.;
datalines;
1 1 01-01-2010 01-02-2010 02-01-2010 df200
1 1 01-01-2010 01-02-2010 02-03-2010 df100
1 1 01-01-2010 01-02-2010 04-03-2010 df147
1 2 03-03-2010 31-03-2010 04-03-2010 df147
1 2 03-03-2010 31-03-2010 04-03-2010 df200
;
run;

proc sql;
create table want as
select distinct a.* from
have a
where a.date_of_diagnosis
 not in (
   select date_of_diagnosis from have b
   where
   b.Admission_date &amp;lt;= a.date_of_diagnosis &amp;lt;= b.Discharge_date
   and
   b.Admission_date ne a.Admission_date
 )
;
quit;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;Record_    admission_    Admission_    Discharge_      date_of_
   id        number         date          date        diagnosis    diagnosis

   1            1        01-01-2010    01-02-2010    02-01-2010      df200  
   1            1        01-01-2010    01-02-2010    02-03-2010      df100  
   1            2        03-03-2010    31-03-2010    04-03-2010      df147  
   1            2        03-03-2010    31-03-2010    04-03-2010      df200  
&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Apr 2018 08:44:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Restriction-of-data-based-on-dates/m-p/455064#M115070</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-04-18T08:44:28Z</dc:date>
    </item>
    <item>
      <title>Re: Restriction of data based on dates.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Restriction-of-data-based-on-dates/m-p/455116#M115098</link>
      <description>&lt;P&gt;Dear KurtBremser&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your answer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I run the same code in my real data i loose half of my data. I cannot see what is wrong. Do I somehow have to build in this has to be within record_id ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Solvej&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Apr 2018 11:51:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Restriction-of-data-based-on-dates/m-p/455116#M115098</guid>
      <dc:creator>Solvej</dc:creator>
      <dc:date>2018-04-18T11:51:10Z</dc:date>
    </item>
    <item>
      <title>Re: Restriction of data based on dates.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Restriction-of-data-based-on-dates/m-p/455117#M115099</link>
      <description>&lt;P&gt;You can see that, with your original example data, my code eliminated exactly the row you wanted eliminated, and kept the 4 others.&lt;/P&gt;
&lt;P&gt;For code tested with certain data, you need to supply that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may need to add&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   and
   b.Record_id = a.Record_id
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;in the where condition of the subquery.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Apr 2018 11:57:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Restriction-of-data-based-on-dates/m-p/455117#M115099</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-04-18T11:57:00Z</dc:date>
    </item>
    <item>
      <title>Re: Restriction of data based on dates.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Restriction-of-data-based-on-dates/m-p/455486#M115214</link>
      <description>&lt;P&gt;Dear KurtBremser&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you. I think It works now. However I would like to see the observations that I delete. How can I build this into the sql statement?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Solvej&lt;/P&gt;</description>
      <pubDate>Thu, 19 Apr 2018 07:29:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Restriction-of-data-based-on-dates/m-p/455486#M115214</guid>
      <dc:creator>Solvej</dc:creator>
      <dc:date>2018-04-19T07:29:05Z</dc:date>
    </item>
    <item>
      <title>Re: Restriction of data based on dates.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Restriction-of-data-based-on-dates/m-p/455487#M115215</link>
      <description>&lt;P&gt;You can restructure the whole statement so that a flag is set, or you can create a second table with the inverse condition:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select distinct a.* from
have a
where a.date_of_diagnosis not in (
  select date_of_diagnosis from have b
  where
  b.Admission_date &amp;lt;= a.date_of_diagnosis &amp;lt;= b.Discharge_date
  and
  b.Admission_date ne a.Admission_date
  and
  b.Record_id = a.Record_id
)
;
create table deletes as
select distinct a.* from
have a
where a.date_of_diagnosis in (
  select date_of_diagnosis from have b
  where
  b.Admission_date &amp;lt;= a.date_of_diagnosis &amp;lt;= b.Discharge_date
  and
  b.Admission_date ne a.Admission_date
  and
  b.Record_id = a.Record_id
)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Apr 2018 07:35:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Restriction-of-data-based-on-dates/m-p/455487#M115215</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-04-19T07:35:06Z</dc:date>
    </item>
    <item>
      <title>Re: Restriction of data based on dates.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Restriction-of-data-based-on-dates/m-p/455499#M115221</link>
      <description>&lt;P&gt;&lt;SPAN class="token procnames"&gt;Hi Again &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token procnames"&gt;When I run the code I delete 14 observations with part one but end up with 0 observations in part 2. Have you changed more than what I have but in bold and with underscore?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;sql&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;BR /&gt;create &lt;SPAN class="token statement"&gt;table&lt;/SPAN&gt; want as &lt;SPAN class="token statement"&gt;select&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;distinct&lt;/SPAN&gt; a&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;from&lt;/SPAN&gt;&lt;BR /&gt;have a&lt;BR /&gt;&lt;SPAN class="token statement"&gt;where&lt;/SPAN&gt; a&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;date_of_diagnosis &lt;SPAN class="token operator"&gt;not&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp; &lt;SPAN class="token statement"&gt;select&lt;/SPAN&gt; date_of_diagnosis &lt;SPAN class="token keyword"&gt;from&lt;/SPAN&gt; have b&lt;BR /&gt;&amp;nbsp; &lt;SPAN class="token statement"&gt;where&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp; b&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;Admission_date &lt;SPAN class="token operator"&gt;&amp;lt;=&lt;/SPAN&gt; a&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;date_of_diagnosis &lt;SPAN class="token operator"&gt;&amp;lt;=&lt;/SPAN&gt; b&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;Discharge_date&lt;BR /&gt;&amp;nbsp; and&lt;BR /&gt;&amp;nbsp; b&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;Admission_date &lt;SPAN class="token operator"&gt;ne&lt;/SPAN&gt; a&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;Admission_date&lt;BR /&gt;&amp;nbsp; and&lt;BR /&gt;&amp;nbsp; b&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;Record_id &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; a&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;Record_id&lt;BR /&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;BR /&gt;create &lt;SPAN class="token statement"&gt;table&lt;/SPAN&gt;&lt;U&gt; &lt;STRONG&gt;deletes&lt;/STRONG&gt;&lt;/U&gt; as&lt;BR /&gt;&lt;SPAN class="token statement"&gt;select&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;distinct&lt;/SPAN&gt; a&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;from&lt;/SPAN&gt;&lt;BR /&gt;have a&lt;BR /&gt;&lt;SPAN class="token statement"&gt;where&lt;/SPAN&gt; a&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;date_of_diagnosis &lt;STRONG&gt;&lt;U&gt;&lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt;&lt;/U&gt;&lt;/STRONG&gt; &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp; &lt;SPAN class="token statement"&gt;select&lt;/SPAN&gt; date_of_diagnosis &lt;SPAN class="token keyword"&gt;from&lt;/SPAN&gt; have b&lt;BR /&gt;&amp;nbsp; &lt;SPAN class="token statement"&gt;where&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp; b&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;Admission_date &lt;SPAN class="token operator"&gt;&amp;lt;=&lt;/SPAN&gt; a&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;date_of_diagnosis &lt;SPAN class="token operator"&gt;&amp;lt;=&lt;/SPAN&gt; b&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;Discharge_date&lt;BR /&gt;&amp;nbsp; and&lt;BR /&gt;&amp;nbsp; b&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;Admission_date &lt;SPAN class="token operator"&gt;ne&lt;/SPAN&gt; a&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;Admission_date&lt;BR /&gt;&amp;nbsp; and&lt;BR /&gt;&amp;nbsp; b&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;Record_id &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; a&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;Record_id&lt;BR /&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards Solvej&lt;/P&gt;</description>
      <pubDate>Thu, 19 Apr 2018 08:25:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Restriction-of-data-based-on-dates/m-p/455499#M115221</guid>
      <dc:creator>Solvej</dc:creator>
      <dc:date>2018-04-19T08:25:30Z</dc:date>
    </item>
    <item>
      <title>Re: Restriction of data based on dates.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Restriction-of-data-based-on-dates/m-p/455502#M115223</link>
      <description>&lt;P&gt;I can only work with the data you gave us:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input
  Record_id
  admission_number
  (Admission_date Discharge_date date_of_diagnosis) (:ddmmyy10.)
  diagnosis $
;
format Admission_date Discharge_date date_of_diagnosis ddmmyyd10.;
datalines;
1 1 01-01-2010 01-02-2010 02-01-2010 df200
1 1 01-01-2010 01-02-2010 02-03-2010 df100
1 1 01-01-2010 01-02-2010 04-03-2010 df147
1 2 03-03-2010 31-03-2010 04-03-2010 df147
1 2 03-03-2010 31-03-2010 04-03-2010 df200
;
run;

proc sql;
create table want as
select distinct a.* from
have a
where a.date_of_diagnosis not in (
  select date_of_diagnosis from have b
  where
  b.Admission_date &amp;lt;= a.date_of_diagnosis &amp;lt;= b.Discharge_date
  and
  b.Admission_date ne a.Admission_date
  and
  b.Record_id = a.Record_id
)
;
create table deletes as
select distinct a.* from
have a
where a.date_of_diagnosis in (
  select date_of_diagnosis from have b
  where
  b.Admission_date &amp;lt;= a.date_of_diagnosis &amp;lt;= b.Discharge_date
  and
  b.Admission_date ne a.Admission_date
  and
  b.Record_id = a.Record_id
)
;
quit;

proc print data=have noobs;
run;

proc print data=want noobs;
run;

proc print data=deletes noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;result:&lt;/P&gt;
&lt;PRE&gt;Record_    admission_    Admission_    Discharge_      date_of_
   id        number         date          date        diagnosis    diagnosis

   1            1        01-01-2010    01-02-2010    02-01-2010      df200  
   1            1        01-01-2010    01-02-2010    02-03-2010      df100  
   1            1        01-01-2010    01-02-2010    04-03-2010      df147  
   1            2        03-03-2010    31-03-2010    04-03-2010      df147  
   1            2        03-03-2010    31-03-2010    04-03-2010      df200  

Record_    admission_    Admission_    Discharge_      date_of_
   id        number         date          date        diagnosis    diagnosis

   1            1        01-01-2010    01-02-2010    02-01-2010      df200  
   1            1        01-01-2010    01-02-2010    02-03-2010      df100  
   1            2        03-03-2010    31-03-2010    04-03-2010      df147  
   1            2        03-03-2010    31-03-2010    04-03-2010      df200  

Record_    admission_    Admission_    Discharge_      date_of_
   id        number         date          date        diagnosis    diagnosis

   1            1        01-01-2010    01-02-2010    04-03-2010      df147  
&lt;/PRE&gt;
&lt;P&gt;You can see it works with your example data.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Apr 2018 08:32:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Restriction-of-data-based-on-dates/m-p/455502#M115223</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-04-19T08:32:51Z</dc:date>
    </item>
    <item>
      <title>Re: Restriction of data based on dates.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Restriction-of-data-based-on-dates/m-p/459611#M116758</link>
      <description>&lt;P&gt;Hi Again&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can still not get the programme to work and the data structure is to complicated to show here. Could you maybe show me how to flag the information I need instead.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind Regards&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Solvej&lt;/P&gt;</description>
      <pubDate>Thu, 03 May 2018 11:28:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Restriction-of-data-based-on-dates/m-p/459611#M116758</guid>
      <dc:creator>Solvej</dc:creator>
      <dc:date>2018-05-03T11:28:54Z</dc:date>
    </item>
    <item>
      <title>Re: Restriction of data based on dates.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Restriction-of-data-based-on-dates/m-p/459617#M116761</link>
      <description>&lt;P&gt;Coding is driven by the data. Without data, I'd just be wasting time in an information vacuum.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/108044"&gt;@Solvej&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi Again&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can still not get the programme to work and the data structure is to complicated to show here. Could you maybe show me how to flag the information I need instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind Regards&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Solvej&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 May 2018 11:51:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Restriction-of-data-based-on-dates/m-p/459617#M116761</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-05-03T11:51:14Z</dc:date>
    </item>
    <item>
      <title>Re: Restriction of data based on dates.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Restriction-of-data-based-on-dates/m-p/459621#M116763</link>
      <description>&lt;P&gt;&lt;SPAN class="token procnames"&gt;Hi Again &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token procnames"&gt;Okay the data is the same as above. However now I want to flag the data instead of making af new dataset that only contains relevant data. The reason for wanting this is that I don't know if or where there may be a problem and without this knowledge it is impossible for me to make a dataset with the relevant structure. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token procnames"&gt;I hope this makes sence.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token procnames"&gt;Thank you in advance for helping me out. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token procnames"&gt;Kind regards &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token procnames"&gt;Solvej&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token punctuation"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 03 May 2018 12:04:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Restriction-of-data-based-on-dates/m-p/459621#M116763</guid>
      <dc:creator>Solvej</dc:creator>
      <dc:date>2018-05-03T12:04:16Z</dc:date>
    </item>
  </channel>
</rss>

