<?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: check a date between all dates ranges  by groups in SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/check-a-date-between-all-dates-ranges-by-groups-in-SAS/m-p/804375#M316753</link>
    <description>&lt;P&gt;Something like this should do the job:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  call streaminit(123);

  do ID = 1 to 3;
    do date = today()-3 to today()+3;
      mi = rand("integer",-10,10);
      mx = rand("integer",-10,10);
      start_date = date + min(mi,mx);
      end_date   = date + max(mi,mx);
      if date = today() then end_date = .;
      output;
    end;
  end;
  format date start_date end_date yymmdd10.;
  drop mi mx;
run;

data want;
  set have;

  if . &amp;lt; start_date &amp;lt;= end_date then
    flag = start_date &amp;lt;= date &amp;lt;= end_date;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
    <pubDate>Sun, 27 Mar 2022 13:56:11 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2022-03-27T13:56:11Z</dc:date>
    <item>
      <title>check a date between all dates ranges  by groups in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-a-date-between-all-dates-ranges-by-groups-in-SAS/m-p/804350#M316742</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;I have the below dataset in SAS, and I want to produce the "flag" column:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tSAS1_0-1648380965184.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/69845i22DB741E659C91AF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="tSAS1_0-1648380965184.png" alt="tSAS1_0-1648380965184.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I want to do is to check each date for each ID if it's between any date_start and date_end or not, if yes then flag will take 1, else 0&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Thank you in advance!&lt;/P&gt;</description>
      <pubDate>Sun, 27 Mar 2022 11:38:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-a-date-between-all-dates-ranges-by-groups-in-SAS/m-p/804350#M316742</guid>
      <dc:creator>tSAS1</dc:creator>
      <dc:date>2022-03-27T11:38:50Z</dc:date>
    </item>
    <item>
      <title>Re: check a date between all dates ranges  by groups in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-a-date-between-all-dates-ranges-by-groups-in-SAS/m-p/804351#M316743</link>
      <description>&lt;P&gt;Why is flag = 1 in obs 2 and 0 in obs 3?&lt;/P&gt;</description>
      <pubDate>Sun, 27 Mar 2022 11:41:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-a-date-between-all-dates-ranges-by-groups-in-SAS/m-p/804351#M316743</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-03-27T11:41:43Z</dc:date>
    </item>
    <item>
      <title>Re: check a date between all dates ranges  by groups in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-a-date-between-all-dates-ranges-by-groups-in-SAS/m-p/804352#M316744</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;&amp;nbsp;for obs=2 for ID=1, date_start=07/12/1998&amp;lt;=date=01/10/2001&amp;lt;=date_end=01/09/2002 ==&amp;gt; flag=1&lt;BR /&gt;&lt;BR /&gt;and in obs=3 for ID=1, date=01/10/2002 &amp;gt; date_end=01/09/2002 ==&amp;gt; date is not included in any ranges of dates of date_start-date_end that's why flag=0&lt;/P&gt;</description>
      <pubDate>Sun, 27 Mar 2022 11:56:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-a-date-between-all-dates-ranges-by-groups-in-SAS/m-p/804352#M316744</guid>
      <dc:creator>tSAS1</dc:creator>
      <dc:date>2022-03-27T11:56:40Z</dc:date>
    </item>
    <item>
      <title>Re: check a date between all dates ranges  by groups in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-a-date-between-all-dates-ranges-by-groups-in-SAS/m-p/804372#M316750</link>
      <description>&lt;P&gt;If both start and end dates are null then you want 1.&lt;/P&gt;
&lt;P&gt;What if only one of them is null?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;B.&lt;/P&gt;</description>
      <pubDate>Sun, 27 Mar 2022 13:39:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-a-date-between-all-dates-ranges-by-groups-in-SAS/m-p/804372#M316750</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2022-03-27T13:39:21Z</dc:date>
    </item>
    <item>
      <title>Re: check a date between all dates ranges  by groups in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-a-date-between-all-dates-ranges-by-groups-in-SAS/m-p/804374#M316752</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt; if both or one of them is missing, we could skip that line (like it is deleted)</description>
      <pubDate>Sun, 27 Mar 2022 13:44:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-a-date-between-all-dates-ranges-by-groups-in-SAS/m-p/804374#M316752</guid>
      <dc:creator>tSAS1</dc:creator>
      <dc:date>2022-03-27T13:44:50Z</dc:date>
    </item>
    <item>
      <title>Re: check a date between all dates ranges  by groups in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-a-date-between-all-dates-ranges-by-groups-in-SAS/m-p/804375#M316753</link>
      <description>&lt;P&gt;Something like this should do the job:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  call streaminit(123);

  do ID = 1 to 3;
    do date = today()-3 to today()+3;
      mi = rand("integer",-10,10);
      mx = rand("integer",-10,10);
      start_date = date + min(mi,mx);
      end_date   = date + max(mi,mx);
      if date = today() then end_date = .;
      output;
    end;
  end;
  format date start_date end_date yymmdd10.;
  drop mi mx;
run;

data want;
  set have;

  if . &amp;lt; start_date &amp;lt;= end_date then
    flag = start_date &amp;lt;= date &amp;lt;= end_date;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Sun, 27 Mar 2022 13:56:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-a-date-between-all-dates-ranges-by-groups-in-SAS/m-p/804375#M316753</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2022-03-27T13:56:11Z</dc:date>
    </item>
  </channel>
</rss>

