<?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: Creating a dataset based on dates from another dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-dataset-based-on-dates-from-another-dataset/m-p/698864#M213766</link>
    <description>&lt;P&gt;Are these DMY or MDY dates? Supplying dates in ISO-standardized format (YYYY-MM-DD) will prevent such ambiguities.&lt;/P&gt;</description>
    <pubDate>Sat, 14 Nov 2020 10:18:39 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-11-14T10:18:39Z</dc:date>
    <item>
      <title>Creating a dataset based on dates from another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-dataset-based-on-dates-from-another-dataset/m-p/698494#M213634</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have two datasets, DB1 and DB2. DB1 has 3 columns Patid, Mindate and Maxdate with about 1000 rows while DB2 has 150 variables including date variables ADMDATE and Dscdate with about 232000 rows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to have a dataset DB3 which would have the data from DB2 with admdate and dscdate within the range of Mindate and Maxdate of DB1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sample data would be something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DB1&lt;/P&gt;
&lt;P&gt;patid mindate maxdate&lt;BR /&gt;1 3/3/2014 12/3/2014&lt;BR /&gt;2 3/1/2017 9/3/2017&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DB2&lt;/P&gt;
&lt;P&gt;Patid ADMDATE dscdate&lt;BR /&gt;1 1/1/2014 1/3/2014&lt;BR /&gt;1 2/1/2014 2/3/2014&lt;BR /&gt;1 3/1/2014 3/3/2014&lt;BR /&gt;1 4/1/2014 4/3/2014&lt;BR /&gt;1 5/1/2014 5/3/2014&lt;BR /&gt;1 6/1/2014 6/3/2014&lt;BR /&gt;1 7/1/2014 7/3/2014&lt;BR /&gt;1 8/1/2014 8/3/2014&lt;BR /&gt;1 9/1/2014 9/3/2014&lt;BR /&gt;1 10/1/2014 10/3/2014&lt;BR /&gt;1 11/1/2014 11/3/2014&lt;BR /&gt;1 12/1/2014 12/3/2014&lt;BR /&gt;1 1/1/2015 1/3/2015&lt;BR /&gt;1 2/1/2015 2/3/2015&lt;BR /&gt;1 3/1/2016 3/3/2016&lt;BR /&gt;1 4/1/2016 4/3/2016&lt;BR /&gt;2 3/1/2017 3/3/2017&lt;BR /&gt;2 4/1/2017 4/3/2017&lt;BR /&gt;2 5/1/2017 5/3/2017&lt;BR /&gt;2 6/1/2017 6/3/2017&lt;BR /&gt;2 7/1/2017 7/3/2017&lt;BR /&gt;2 8/1/2017 8/3/2017&lt;BR /&gt;2 9/1/2017 9/3/2017&lt;BR /&gt;2 10/1/2017 10/3/2017&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data DB3 (Want)&lt;/P&gt;
&lt;P&gt;1 4/1/2014 4/3/2014&lt;BR /&gt;1 5/1/2014 5/3/2014&lt;BR /&gt;1 6/1/2014 6/3/2014&lt;BR /&gt;1 7/1/2014 7/3/2014&lt;BR /&gt;1 8/1/2014 8/3/2014&lt;BR /&gt;1 9/1/2014 9/3/2014&lt;BR /&gt;1 10/1/2014 10/3/2014&lt;BR /&gt;1 11/1/2014 11/3/2014&lt;BR /&gt;1 12/1/2014 12/3/2014&lt;BR /&gt;2 3/1/2017 3/3/2017&lt;BR /&gt;2 4/1/2017 4/3/2017&lt;BR /&gt;2 5/1/2017 5/3/2017&lt;BR /&gt;2 6/1/2017 6/3/2017&lt;BR /&gt;2 7/1/2017 7/3/2017&lt;BR /&gt;2 8/1/2017 8/3/2017&lt;BR /&gt;2 9/1/2017 9/3/2017&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help would be highly appreciated&lt;/P&gt;</description>
      <pubDate>Thu, 12 Nov 2020 19:23:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-dataset-based-on-dates-from-another-dataset/m-p/698494#M213634</guid>
      <dc:creator>ihtishamsultan</dc:creator>
      <dc:date>2020-11-12T19:23:30Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a dataset based on dates from another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-dataset-based-on-dates-from-another-dataset/m-p/698504#M213638</link>
      <description>&lt;P&gt;You should be a bit more explicit about what the meaning of "admdate and dscdate within the range of Mindate and Maxdate" is.&lt;/P&gt;
&lt;P&gt;There are several considerations that phrase leaves as ambiguous.&lt;/P&gt;
&lt;P&gt;What if Admdate is between Mindate and Maxdate but dscdate is not?&lt;/P&gt;
&lt;P&gt;Or if Dscdate is between Mindate and Maxdate but Admdate is not?&lt;/P&gt;
&lt;P&gt;Do either of these conditions get included or are you only looking for&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Mindate &amp;lt;= admdate &amp;lt;= dscdate &amp;lt;= Maxdate?&lt;/P&gt;</description>
      <pubDate>Thu, 12 Nov 2020 20:00:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-dataset-based-on-dates-from-another-dataset/m-p/698504#M213638</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-11-12T20:00:53Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a dataset based on dates from another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-dataset-based-on-dates-from-another-dataset/m-p/698839#M213751</link>
      <description>&lt;P&gt;What I want is something like this&lt;/P&gt;
&lt;P&gt;Dataset1 has Mindate and Maxdate ( The earliest&amp;nbsp; and the last date that a patient had an encounter- Out patient consultation)&lt;/P&gt;
&lt;P&gt;Dataset2- has admission&amp;nbsp;and discharge record of patients. I would like to extract all records of patients that lie between Minimum and Maximum dates of Dataset1.&lt;/P&gt;
&lt;P&gt;For instance, If a patient has a minimum date of&amp;nbsp;1st Jan 2016 and maximum date of 05th May 2018 in dataset 1, then in dataset2 if the first admission was on 11th May 2014 and last admission&amp;nbsp; 24 December 2019, I want to pull all records of admission, discharge(from dataset2) that are within the range of&amp;nbsp;1st Jan 2016 to&amp;nbsp;05th May 2018&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I believe it is&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Mindate &amp;lt;= ADMDATE- &amp;lt;=Maxdate&lt;/P&gt;</description>
      <pubDate>Sat, 14 Nov 2020 00:37:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-dataset-based-on-dates-from-another-dataset/m-p/698839#M213751</guid>
      <dc:creator>ihtishamsultan</dc:creator>
      <dc:date>2020-11-14T00:37:25Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a dataset based on dates from another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-dataset-based-on-dates-from-another-dataset/m-p/698845#M213752</link>
      <description>&lt;P&gt;Not sure what you are asking for but to check for overlapping intervals use this test:&lt;/P&gt;
&lt;PRE&gt;/* 
Interval (A,B) overlaps Interval (C,D) when A&amp;lt;=D and B&amp;gt;=C

Examples of Overlap:
  A&amp;lt;--&amp;gt;B   A&amp;lt;--&amp;gt;B     A&amp;lt;----&amp;gt;B     A&amp;lt;--&amp;gt;B
C&amp;lt;--&amp;gt;D       C&amp;lt;--&amp;gt;D    C&amp;lt;--&amp;gt;D     C&amp;lt;----&amp;gt;D

Examples of No Overlap:
A&amp;lt;--&amp;gt;B                    A&amp;lt;--&amp;gt;B
       C&amp;lt;--&amp;gt;D     C&amp;lt;--&amp;gt;D

To account for missing values use: .Z&amp;lt;A&amp;lt;=D and B&amp;gt;=C&amp;gt;.Z 

*/

&lt;/PRE&gt;</description>
      <pubDate>Sat, 14 Nov 2020 02:14:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-dataset-based-on-dates-from-another-dataset/m-p/698845#M213752</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-11-14T02:14:19Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a dataset based on dates from another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-dataset-based-on-dates-from-another-dataset/m-p/698864#M213766</link>
      <description>&lt;P&gt;Are these DMY or MDY dates? Supplying dates in ISO-standardized format (YYYY-MM-DD) will prevent such ambiguities.&lt;/P&gt;</description>
      <pubDate>Sat, 14 Nov 2020 10:18:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-dataset-based-on-dates-from-another-dataset/m-p/698864#M213766</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-14T10:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a dataset based on dates from another dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-dataset-based-on-dates-from-another-dataset/m-p/698866#M213767</link>
      <description>&lt;P&gt;See this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data db1;
input patid $ mindate :mmddyy10. maxdate :mmddyy10.;
format mindate maxdate yymmdd10.;
datalines;
1 3/3/2014 12/3/2014
2 3/1/2017 9/3/2017
;
 
data db2;
input patid $ admdate :mmddyy10. dscdate :mmddyy10.;
format admdate dscdate yymmdd10.;
datalines;
1 1/1/2014 1/3/2014
1 2/1/2014 2/3/2014
1 3/1/2014 3/3/2014
1 4/1/2014 4/3/2014
1 5/1/2014 5/3/2014
1 6/1/2014 6/3/2014
1 7/1/2014 7/3/2014
1 8/1/2014 8/3/2014
1 9/1/2014 9/3/2014
1 10/1/2014 10/3/2014
1 11/1/2014 11/3/2014
1 12/1/2014 12/3/2014
1 1/1/2015 1/3/2015
1 2/1/2015 2/3/2015
1 3/1/2016 3/3/2016
1 4/1/2016 4/3/2016
2 3/1/2017 3/3/2017
2 4/1/2017 4/3/2017
2 5/1/2017 5/3/2017
2 6/1/2017 6/3/2017
2 7/1/2017 7/3/2017
2 8/1/2017 8/3/2017
2 9/1/2017 9/3/2017
2 10/1/2017 10/3/2017
;

data db3;
set db2;
if _N_ = 1
then do;
  length mindate maxdate 8;
  declare hash db1 (dataset:"db1");
  db1.definekey("patid");
  db1.definedata("mindate","maxdate");
  db1.definedone();
  call missing(mindate,maxdate);
end;
if
  db1.find() = 0 and
  mindate le admdate le maxdate and
  mindate le dscdate le maxdate
;
drop mindate maxdate;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note how I presented the data as data steps with datalines; this removes any doubts about attributes and contents.&lt;/P&gt;
&lt;P&gt;Please post your source data like this in the future; it's not rocket science, and it greatly helps in finding a valid answer.&lt;/P&gt;</description>
      <pubDate>Sat, 14 Nov 2020 10:27:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-dataset-based-on-dates-from-another-dataset/m-p/698866#M213767</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-14T10:27:39Z</dc:date>
    </item>
  </channel>
</rss>

