<?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 Flagging rows based on dates across two variables that are on different rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Flagging-rows-based-on-dates-across-two-variables-that-are-on/m-p/923016#M363408</link>
    <description>&lt;P&gt;So as the image below shows, this is currently data that is within one data-step.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I'm currently trying to figure out a way in which rows can be flagged which contain the same date or same date + 1; when the end date matches the start date on the following row or if the end date is within a day of the start date on the following row.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Essentially we are checking for when the row has 'chgdt_10' populated and then if the end date matches the start date of the following row or within +1 day(s).&lt;BR /&gt;&lt;BR /&gt;Using the lag function I am able to (testflg) the consecutive records but unable to flag the initial record where the match occurs, so where I've linked the rows with the blue line I would like the very first row to be populated for 'testflg' too.&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="linking dates.JPG" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/95212iDDC5E874FA1AB43E/image-size/large?v=v2&amp;amp;px=999" role="button" title="linking dates.JPG" alt="linking dates.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance for any responses.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 04 Apr 2024 17:18:47 GMT</pubDate>
    <dc:creator>joshCRF</dc:creator>
    <dc:date>2024-04-04T17:18:47Z</dc:date>
    <item>
      <title>Flagging rows based on dates across two variables that are on different rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-rows-based-on-dates-across-two-variables-that-are-on/m-p/923016#M363408</link>
      <description>&lt;P&gt;So as the image below shows, this is currently data that is within one data-step.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I'm currently trying to figure out a way in which rows can be flagged which contain the same date or same date + 1; when the end date matches the start date on the following row or if the end date is within a day of the start date on the following row.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Essentially we are checking for when the row has 'chgdt_10' populated and then if the end date matches the start date of the following row or within +1 day(s).&lt;BR /&gt;&lt;BR /&gt;Using the lag function I am able to (testflg) the consecutive records but unable to flag the initial record where the match occurs, so where I've linked the rows with the blue line I would like the very first row to be populated for 'testflg' too.&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="linking dates.JPG" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/95212iDDC5E874FA1AB43E/image-size/large?v=v2&amp;amp;px=999" role="button" title="linking dates.JPG" alt="linking dates.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance for any responses.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2024 17:18:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-rows-based-on-dates-across-two-variables-that-are-on/m-p/923016#M363408</guid>
      <dc:creator>joshCRF</dc:creator>
      <dc:date>2024-04-04T17:18:47Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging rows based on dates across two variables that are on different rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-rows-based-on-dates-across-two-variables-that-are-on/m-p/923021#M363409</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
start='25sep2021'd; end='28apr2022'd; output;
start='28apr2022'd; end='15sep2022'd; output;
start='15sep2022'd; end='03oct2022'd; output;
format start end date9.;
run;
data have; set have; rowid=_N_; run;

/* you probably have this now : */
/*
data want(drop=a);
 set have;
 a=lag(end);
 if start=a then testflg=1;
run;
*/

/* you need this : */
/* just an example -- other solutions are possible !! */
proc timedata data=have out=wanthmmm outarray=work.testflg_array print=(arrays);
   id rowid interval=day;
   vars start end;
   outarrays testflg;
      do t= 1 to dim(end);
         if end[t]   = start[t+1] then do; testflg[t]=1; end;
		 else do; testflg[t]=0; end;
      end;
run;

data work.testflg_array;
 set work.testflg_array;
 keep  start end testflg;
 format start end date9.;
run;
/* end of program */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;PROC TIMEDATA is part of SAS/ETS software.&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2024 18:05:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-rows-based-on-dates-across-two-variables-that-are-on/m-p/923021#M363409</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2024-04-04T18:05:29Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging rows based on dates across two variables that are on different rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-rows-based-on-dates-across-two-variables-that-are-on/m-p/923027#M363413</link>
      <description>&lt;P&gt;I think you want to look ahead.&amp;nbsp; You should be able to find lots of discussion here in the community.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Look-Ahead-and-Look-Back/ta-p/475772" target="_blank" rel="noopener"&gt;Look-Ahead and Look-Back - SAS Support Communities&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Is a good start the part from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;is really good.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you post some useable data in text format not a picture you will get more helpful solutions.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2024 18:42:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-rows-based-on-dates-across-two-variables-that-are-on/m-p/923027#M363413</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2024-04-04T18:42:28Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging rows based on dates across two variables that are on different rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-rows-based-on-dates-across-two-variables-that-are-on/m-p/923076#M363430</link>
      <description>&lt;P&gt;Why did you flag the last line (START=05MAR2024), but not flag its predecessor (END=04MAR2024)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the absence of usable sample data in the form of a working DATA step, here is my untested guess as to what you want.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=nxt_:);
  set have ;
  by chgdt_10 notsorted;
  merge have
        have (firstobs=2 keep=chgdt_10 start rename=(chgdt_10=nxt_chgdt start=nxt_start)) ;

  retain _beg_series  _end_series 0;
  _beg_series = (first.chgdt_10=1 and chgdt_10^=.);
  _end_series = (last.chgdt_10=1  and nxt_chgdt^=.);

  flag=  (start-1 &amp;lt;= lag(end)  and _beg_series=0)
         or
         (end+1   &amp;gt;= nxt_start and _end_series=0);
run;
  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This assume that each series&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;is sorted by START and&lt;/LI&gt;
&lt;LI&gt;starts with a non-missing value for CHGDT_10.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Fri, 05 Apr 2024 01:59:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-rows-based-on-dates-across-two-variables-that-are-on/m-p/923076#M363430</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-04-05T01:59:41Z</dc:date>
    </item>
  </channel>
</rss>

