<?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 confirm date within special start date and end date ?? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-confirm-date-within-special-start-date-and-end-date/m-p/805493#M317316</link>
    <description>Thank you so much! It works. This is my first time posting a question. Thank you for your suggestion, I will provide better sample dataset next time if I have more questions later!</description>
    <pubDate>Fri, 01 Apr 2022 12:51:01 GMT</pubDate>
    <dc:creator>t1ilie</dc:creator>
    <dc:date>2022-04-01T12:51:01Z</dc:date>
    <item>
      <title>How to confirm date within special start date and end date ??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-confirm-date-within-special-start-date-and-end-date/m-p/805418#M317270</link>
      <description>&lt;P&gt;Hi, all&lt;/P&gt;&lt;P&gt;I have 2 datasets, sample datasets below:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; data1 :&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; id&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;sequence&lt;/P&gt;&lt;P&gt;234123&amp;nbsp; 2012-02-04&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;234123&amp;nbsp; 2012-01-26&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;234124&amp;nbsp; 2012-02-24&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;234124&amp;nbsp; 2015-05-05&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;data2:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; id&amp;nbsp; &amp;nbsp; &amp;nbsp; startdate&amp;nbsp; &amp;nbsp; &amp;nbsp; enddate&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;sequence&lt;/P&gt;&lt;P&gt;234123&amp;nbsp; &amp;nbsp;2010-01-01&amp;nbsp; &amp;nbsp; 2012-01-25&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;234123&amp;nbsp; &amp;nbsp;2012-01-28&amp;nbsp; &amp;nbsp; 2012-03-05&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;234123&amp;nbsp; &amp;nbsp;2012-02-14&amp;nbsp; &amp;nbsp; 2012-05-07&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;234124&amp;nbsp; &amp;nbsp;2012-01-25&amp;nbsp; &amp;nbsp; 2012-02-25&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;234124&amp;nbsp; &amp;nbsp;2012-02-23&amp;nbsp; &amp;nbsp; 2012-03-24&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;234124&amp;nbsp; &amp;nbsp;2015-06-24&amp;nbsp; &amp;nbsp; 2015-07-25&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;For the same id, I want to calculate if its date is within any corresponding start date and end date, if the date is within, then give the flag=yes, else flag=no. Each date should have one flag. The final results are below:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; id&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;sequence&amp;nbsp; &amp;nbsp; flag&lt;/P&gt;&lt;P&gt;234123&amp;nbsp; 2012-02-04&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; yes&lt;/P&gt;&lt;P&gt;234123&amp;nbsp; 2012-01-26&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; no&lt;/P&gt;&lt;P&gt;234124&amp;nbsp; 2012-02-24&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; yes&lt;/P&gt;&lt;P&gt;234124&amp;nbsp; 2015-05-05&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; no&lt;/P&gt;&lt;P&gt;&amp;nbsp;Thank you for any help!&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2022 01:08:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-confirm-date-within-special-start-date-and-end-date/m-p/805418#M317270</guid>
      <dc:creator>t1ilie</dc:creator>
      <dc:date>2022-04-01T01:08:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to confirm date within special start date and end date ??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-confirm-date-within-special-start-date-and-end-date/m-p/805419#M317271</link>
      <description>How does sequencing relate to this?&lt;BR /&gt;If it is the same ID, same sequence, then I think the flag value for the first obs of the result (id=234123, sequence=1) should be "no".</description>
      <pubDate>Fri, 01 Apr 2022 01:28:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-confirm-date-within-special-start-date-and-end-date/m-p/805419#M317271</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2022-04-01T01:28:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to confirm date within special start date and end date ??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-confirm-date-within-special-start-date-and-end-date/m-p/805420#M317272</link>
      <description>For the same ID, each unique date should be calculated, so I give the sequence.</description>
      <pubDate>Fri, 01 Apr 2022 01:37:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-confirm-date-within-special-start-date-and-end-date/m-p/805420#M317272</guid>
      <dc:creator>t1ilie</dc:creator>
      <dc:date>2022-04-01T01:37:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to confirm date within special start date and end date ??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-confirm-date-within-special-start-date-and-end-date/m-p/805422#M317274</link>
      <description>The first obs should be yes because "2012-02-04" is within " 2012-01-28 2012-03-05".</description>
      <pubDate>Fri, 01 Apr 2022 01:42:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-confirm-date-within-special-start-date-and-end-date/m-p/805422#M317274</guid>
      <dc:creator>t1ilie</dc:creator>
      <dc:date>2022-04-01T01:42:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to confirm date within special start date and end date ??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-confirm-date-within-special-start-date-and-end-date/m-p/805423#M317275</link>
      <description>Sorry for the confusion, the two 'sequence' variables in the two datasets are not related. You can ignore them.</description>
      <pubDate>Fri, 01 Apr 2022 01:52:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-confirm-date-within-special-start-date-and-end-date/m-p/805423#M317275</guid>
      <dc:creator>t1ilie</dc:creator>
      <dc:date>2022-04-01T01:52:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to confirm date within special start date and end date ??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-confirm-date-within-special-start-date-and-end-date/m-p/805438#M317285</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/316654"&gt;@t1ilie&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;For the same ID, each unique date should be calculated, so I give the sequence.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So, how should "sequence" be used in this task?&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2022 06:51:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-confirm-date-within-special-start-date-and-end-date/m-p/805438#M317285</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-04-01T06:51:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to confirm date within special start date and end date ??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-confirm-date-within-special-start-date-and-end-date/m-p/805443#M317288</link>
      <description>&lt;P&gt;Assuming that id and sequence in data1 should be used to identify the ranges to check in data2:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   
   if _n_ = 1 then do;
      if 0 then set work.sequences;
      
      declare hash s(dataset: 'work.sequences', multidata: 'yes');
      s.defineKey('id', 'sequence');
      s.defineData('startdate', 'enddate');
      s.defineDone();
   end;
  
   rc = s.find();
   flag = 0;
   
   do while (rc = 0);
      flag = (startdate &amp;lt;= date &amp;lt;= enddate) or flag;
      rc = not (s.find_next() = 0 and not flag);
   end;
   
   drop rc;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;have = data1&lt;/P&gt;
&lt;P&gt;sequences = data2&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2022 07:18:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-confirm-date-within-special-start-date-and-end-date/m-p/805443#M317288</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-04-01T07:18:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to confirm date within special start date and end date ??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-confirm-date-within-special-start-date-and-end-date/m-p/805446#M317289</link>
      <description>&lt;P&gt;Does below work for you?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have_date;
  input id date:yymmdd10.;
  format date date9.;
datalines;
234123 2012-02-04
234123 2012-01-26
234124 2012-02-24
234124 2015-05-05
;

data have_daterange;
  input id startdate:yymmdd10. enddate:yymmdd10.;
  format startdate enddate date9.;
datalines;
234123 2010-01-01 2012-01-25
234123 2012-01-28 2012-03-05
234123 2012-02-14 2012-05-07
234124 2012-01-25 2012-02-25
234124 2012-02-23 2012-03-24
234124 2015-06-24 2015-07-25
;

data want;
  if _n_=1 then
    do;
      if 0 then set have_daterange;
      dcl hash h1(dataset:'have_daterange', multidata:'y');
      h1.defineKey('id');
      h1.defineData('startdate','enddate');
      h1.defineDone();
      drop startdate enddate;
    end;
  call missing(of _all_);

  set have_date;

  inrange_flg=0;
  do while(h1.do_over() eq 0);
    if startdate&amp;lt;=date&amp;lt;=enddate then
      do;
        inrange_flg=1;
        leave;
      end;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;...and it would help us help you if you could provide sample data via a working data step as done in above code as this then gives us the time to deal with your question instead of preparing the sample data.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2022 07:31:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-confirm-date-within-special-start-date-and-end-date/m-p/805446#M317289</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-04-01T07:31:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to confirm date within special start date and end date ??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-confirm-date-within-special-start-date-and-end-date/m-p/805489#M317313</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data data1 ;
input      id        date  :yymmdd10.          sequence;
format date  yymmdd10.  ;
cards;
234123  2012-02-04         1
234123  2012-01-26         2
234124  2012-02-24         1
234124  2015-05-05         2
;
data  data2;
input  id      startdate    :yymmdd10.    enddate      :yymmdd10.         sequence ;
format  startdate     enddate    yymmdd10. ;
cards;
234123   2010-01-01    2012-01-25      1
234123   2012-01-28    2012-03-05      2
234123   2012-02-14    2012-05-07      3
234124   2012-01-25    2012-02-25      1
234124   2012-02-23    2012-03-24      2
234124   2015-06-24    2015-07-25      3
;

data temp;
 set data2;
 do date=startdate  to   enddate;
  output;
 end;
keep id date;
run;
data want;
if _n_=1 then do;
 declare hash h(dataset:'temp',hashexp:20);
 h.definekey('id','date');
 h.definedone();
end;
set data1;
flag=ifc( h.check()=0 ,'yes','no ');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 Apr 2022 12:36:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-confirm-date-within-special-start-date-and-end-date/m-p/805489#M317313</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-04-01T12:36:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to confirm date within special start date and end date ??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-confirm-date-within-special-start-date-and-end-date/m-p/805493#M317316</link>
      <description>Thank you so much! It works. This is my first time posting a question. Thank you for your suggestion, I will provide better sample dataset next time if I have more questions later!</description>
      <pubDate>Fri, 01 Apr 2022 12:51:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-confirm-date-within-special-start-date-and-end-date/m-p/805493#M317316</guid>
      <dc:creator>t1ilie</dc:creator>
      <dc:date>2022-04-01T12:51:01Z</dc:date>
    </item>
  </channel>
</rss>

