<?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: Clean date in a longitudinal data in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Clean-date-in-a-longitudinal-data/m-p/613369#M18404</link>
    <description>&lt;P&gt;Thanks, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;, for your time and great help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I checked the results generated from your code and found that both deleted record 6 and 12, instead of 5 and 11. I have to check the code on the original data whether the they generate desired results or not. But I would prefer to delete the right one and correct the ones planned, i.e., record 6 and 12.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, the second code deleted one additional record -&amp;nbsp;14.&lt;/P&gt;</description>
    <pubDate>Sat, 21 Dec 2019 00:56:00 GMT</pubDate>
    <dc:creator>NanZ</dc:creator>
    <dc:date>2019-12-21T00:56:00Z</dc:date>
    <item>
      <title>Clean date in a longitudinal data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Clean-date-in-a-longitudinal-data/m-p/613293#M18389</link>
      <description>&lt;P&gt;Hello SAS Users,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to clean a longitudinal data set for people with multiple visits. The recorded date however involves mistakes/unreasonable dates. For example, the same check-in (datin) and check-out date (datout). I tried to add one day to the check-out date or remove one day to the check-in date, depending on the date of visit before the same check-in/out date, with using lead and lag function. The removing one day code works but not the adding one day code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for any suggestions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Merry Christmas!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The resulted data&amp;nbsp;should look like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Data WANT&lt;/STRONG&gt;&lt;BR /&gt;1 1 2&lt;BR /&gt;1 2 3&lt;BR /&gt;1 3 4&lt;BR /&gt;1 4 5&lt;BR /&gt;(deleted, because the&amp;nbsp;check-out date in this period is later than&amp;nbsp;the check-in date of the next period&amp;nbsp;, 20&amp;gt;6)&lt;BR /&gt;1&amp;nbsp;5 6 (or 6 7 but should not beyond 9, the next check in date)&lt;BR /&gt;1 9 10&lt;BR /&gt;1 10 11&lt;BR /&gt;1 11 12&lt;BR /&gt;1 12 13&lt;BR /&gt;(deleted)&lt;BR /&gt;1 14 15&amp;nbsp;&amp;nbsp;(or&amp;nbsp;13&amp;nbsp;14 but should not cross with previous check-out date or&amp;nbsp;next check in date)&lt;BR /&gt;1 15 16&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(or&amp;nbsp;14&amp;nbsp;15 but should not cross with&amp;nbsp;previous check-out date or&amp;nbsp;next check in date)&lt;BR /&gt;1 16 17&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;** Example data and tried code ;&lt;/P&gt;&lt;P&gt;data &lt;STRONG&gt;HAVE&lt;/STRONG&gt;;&lt;BR /&gt;input clientid datin datout ;&lt;BR /&gt;datalines;&lt;BR /&gt;1 1 2&lt;BR /&gt;1 2 2&lt;BR /&gt;1 3 3&lt;BR /&gt;1 4 4&lt;BR /&gt;1 5 20&lt;BR /&gt;1 6 6&lt;BR /&gt;1 9 10&lt;BR /&gt;1 11 11&lt;BR /&gt;1 12 12&lt;BR /&gt;1 13 13&lt;BR /&gt;1 14 16&lt;BR /&gt;1 15 15&lt;BR /&gt;1 16 16&lt;BR /&gt;1 16 17&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc expand data= h1 out= h1;&lt;BR /&gt;&amp;nbsp;convert datin = lead_datin /transformout = (lead 1);&lt;BR /&gt;&amp;nbsp;convert datout = lead_datout /transformout = (lead 1);&lt;BR /&gt;&amp;nbsp;by clientid;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;* Create lag date;&lt;BR /&gt;&amp;nbsp;data h1 ;&lt;BR /&gt;&amp;nbsp;format clientid flag_inout_sameday datin datout date_in date_out lead_datin lead_datout lag_datin lag_datout time&amp;nbsp; ;&lt;BR /&gt;&amp;nbsp;set h1 ;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;date_in=datin;&lt;BR /&gt;&amp;nbsp;date_out=datout;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;* The same day in/out;&lt;BR /&gt;&amp;nbsp;if datin=datout and datin~=. then flag_inout_sameday = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;* unreasonable datout ;&lt;BR /&gt;&amp;nbsp;if datout&amp;gt;lead_datout and lead_datout~=. then delete ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;by clientid;&lt;BR /&gt;&amp;nbsp;lag_datin = ifn(first.clientid, . , lag(datin));&lt;BR /&gt;&amp;nbsp;lag_datout = ifn(first.clientid, . , lag(datout));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;*** Clean records with Same day in/out ***;&lt;BR /&gt;&amp;nbsp;if &amp;nbsp;&amp;nbsp;&amp;nbsp;not first.clientid and flag_inout_sameday = 1 and datin&amp;gt;lag_datout then date_in = datin - 1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;else if not first.clientid and flag_inout_sameday = 1 and datin&amp;lt;lead_datin then date_out = datout + 1;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Dec 2019 20:34:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Clean-date-in-a-longitudinal-data/m-p/613293#M18389</guid>
      <dc:creator>NanZ</dc:creator>
      <dc:date>2019-12-23T20:34:02Z</dc:date>
    </item>
    <item>
      <title>Re: Clean date in a longitudinal data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Clean-date-in-a-longitudinal-data/m-p/613299#M18390</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/304333"&gt;@NanZ&lt;/a&gt;&amp;nbsp; I am not quite getting the intuition of your exercise as the sample suggests only 1 day interval between datein and dateout? Hmm such lucky patients or hotel customers who occupy just for a day.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway FWIW&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data h1;
input clientid datin datout ;
datalines;
1 1 2
1 2 2
1 3 3
1 4 4
1 5 7
1 6 6
1 9 10
1 11 11
1 12 12
1 13 13
1 14 16
1 15 15
1 16 16
1 16 17
;
 

data want;
 do until(last.clientid);
  set h1(drop=datout);
  by clientid;
  _min=min(_min,datin);
  _max=max(_max,datin);
 end;
 do _n_=_min to _max;
  datin=_n_;
  dateout=datin+1;
  output;
 end;
 drop _:;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;A little more comprehensive information would help&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Dec 2019 18:56:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Clean-date-in-a-longitudinal-data/m-p/613299#M18390</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-12-20T18:56:29Z</dc:date>
    </item>
    <item>
      <title>Re: Clean date in a longitudinal data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Clean-date-in-a-longitudinal-data/m-p/613317#M18392</link>
      <description>&lt;P&gt;Thanks, &lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205" target="_self"&gt;&lt;SPAN class="login-bold"&gt;novinosrin,&lt;/SPAN&gt;&lt;/A&gt; for your quick response. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The synthetic data is shelter records&amp;nbsp;but not hospital ones. Some shelters require people to register every day, some may not do so. A shelter may require daily registration in some specific&amp;nbsp;periods (for example, winter)&amp;nbsp;but not other periods. Because of that, the data contains the combination of&amp;nbsp;the two types of stays&amp;nbsp;across people/shelters.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the same day&amp;nbsp;check-in/out record, it could be a person came to the door at midnight, a mistake&amp;nbsp;to input the date, or some other unknow reasons. Unless these records&amp;nbsp;are apparently incorrect, all obs are planned to&amp;nbsp;be kept.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Actually, my final dataset should look like the following - the start and end date for a continuous stay&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Final data format:&lt;/P&gt;&lt;P&gt;id datin datout&lt;/P&gt;&lt;P&gt;1 1 6&lt;BR /&gt;1 9 13&lt;/P&gt;&lt;P&gt;1 14 17&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Corresponding to the "cleaned" data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;clientid datin datout&lt;BR /&gt;1 1 2&lt;BR /&gt;1 2 3&lt;BR /&gt;1 3 4&lt;BR /&gt;1 4 5&lt;BR /&gt;(deleted) (A mistake in my original post. Revision has been done)&lt;/P&gt;&lt;P&gt;1 5 6&lt;BR /&gt;1 9 10&lt;BR /&gt;1 10 11&lt;BR /&gt;1 11 12&lt;BR /&gt;1 12 13&lt;BR /&gt;(deleted)&lt;BR /&gt;1 14 15&amp;nbsp;&amp;nbsp;&lt;BR /&gt;1 15 16&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;1 16 17&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/304333"&gt;@NanZ&lt;/a&gt;&amp;nbsp; I am not quite getting the intuition of your exercise as the sample suggests only 1 day interval between datein and dateout? Hmm such lucky patients or hotel customers who occupy just for a day.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyway FWIW&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data h1;
input clientid datin datout ;
datalines;
1 1 2
1 2 2
1 3 3
1 4 4
1 5 7
1 6 6
1 9 10
1 11 11
1 12 12
1 13 13
1 14 16
1 15 15
1 16 16
1 16 17
;
 

data want;
 do until(last.clientid);
  set h1(drop=datout);
  by clientid;
  _min=min(_min,datin);
  _max=max(_max,datin);
 end;
 do _n_=_min to _max;
  datin=_n_;
  dateout=datin+1;
  output;
 end;
 drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;A little more comprehensive information would help&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Dec 2019 20:05:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Clean-date-in-a-longitudinal-data/m-p/613317#M18392</guid>
      <dc:creator>NanZ</dc:creator>
      <dc:date>2019-12-20T20:05:22Z</dc:date>
    </item>
    <item>
      <title>Re: Clean date in a longitudinal data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Clean-date-in-a-longitudinal-data/m-p/613321#M18393</link>
      <description>&lt;P&gt;Hmm, still not able to comprehend properly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Okay, To keep it simple, can you provide the following&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. A sample data of what you HAVE (your input dataset)&lt;/P&gt;
&lt;P&gt;2. A sample data of what you WANT( your output dataset for the corresponding input)&lt;/P&gt;
&lt;P&gt;3. A brief explanation/narrative of the logic to derive the WANT relevant to 1 and 2.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Should i assume&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#339966"&gt;&lt;STRONG&gt;1. is&amp;nbsp;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Final data format:&lt;/P&gt;
&lt;P&gt;id datin datout&lt;/P&gt;
&lt;P&gt;1 1 6&lt;BR /&gt;1 9 13&lt;/P&gt;
&lt;P&gt;1 14 17&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#008000"&gt;&lt;STRONG&gt;&amp;nbsp;2 is&amp;nbsp;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Corresponding to the "cleaned" data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;clientid datin datout&lt;BR /&gt;1 1 2&lt;BR /&gt;1 2 3&lt;BR /&gt;1 3 4&lt;BR /&gt;1 4 5&lt;BR /&gt;(deleted) (A mistake in my original post. Revision has been done)&lt;/P&gt;
&lt;P&gt;1 5 6&lt;BR /&gt;1 9 10&lt;BR /&gt;1 10 11&lt;BR /&gt;1 11 12&lt;BR /&gt;1 12 13&lt;BR /&gt;(deleted)&lt;BR /&gt;1 14 15&amp;nbsp;&amp;nbsp;&lt;BR /&gt;1 15 16&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;1 16 17&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#339966"&gt;If yes, then&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input id datin datout;
cards;
1 1 6
1 9 13
1 14 17
;

data want;
 set have;
 do datin=datin to datout-1;
  datout=datin+1;
  output;
 end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Dec 2019 20:15:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Clean-date-in-a-longitudinal-data/m-p/613321#M18393</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-12-20T20:15:57Z</dc:date>
    </item>
    <item>
      <title>Re: Clean date in a longitudinal data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Clean-date-in-a-longitudinal-data/m-p/613344#M18394</link>
      <description>&lt;P&gt;Let me try but I am not sure I can make it clearer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1. HAVE&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;clientid datin datout&lt;/P&gt;&lt;P&gt;1 1 2&lt;BR /&gt;1 2 2&lt;BR /&gt;1 3 3&lt;BR /&gt;1 4 4&lt;BR /&gt;1 5 20&lt;BR /&gt;1 6 6&lt;BR /&gt;1 9 10&lt;BR /&gt;1 11 11&lt;BR /&gt;1 12 12&lt;BR /&gt;1 13 13&lt;BR /&gt;1 14 16&lt;BR /&gt;1 15 15&lt;BR /&gt;1 16 16&lt;BR /&gt;1 16 17&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2. WANT&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;clientid datin datout&lt;/P&gt;&lt;P&gt;1 1 2&lt;BR /&gt;1 2 3&lt;BR /&gt;1 3 4&lt;BR /&gt;1 4 5&lt;BR /&gt;(deleted)&lt;BR /&gt;1&amp;nbsp;5 6&lt;BR /&gt;1 9 10&lt;BR /&gt;1 10 11&lt;BR /&gt;1 11 12&lt;BR /&gt;1 12 13&lt;BR /&gt;(deleted)&lt;BR /&gt;1 14 15&amp;nbsp;&lt;BR /&gt;1 15 16&amp;nbsp;&lt;BR /&gt;1 16 17&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Logic:&lt;/P&gt;&lt;P&gt;Change the same day in/out to sequential days in/out, base on the previous/next&amp;nbsp;record.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example&lt;/P&gt;&lt;P&gt;1.&amp;nbsp;For the second record. The original check in/out date is 2 2. I would like to change it to 2 3, because the previous&amp;nbsp;record is 1 2. Or&amp;nbsp;the check in date in the second record&amp;nbsp;should not before the previous check out date. Consequently, the 3rd record, 3 3, will become 3 4 and so on&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To summarize, adding one day to the check out date because of the&amp;nbsp;record with check in/out date 1 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. Change the second record to the last&amp;nbsp;from 16 16 (check in/out) to 15 16 due to the last record has value 16 17 (check in/out).&amp;nbsp;&amp;nbsp;Because the check out date in the second to the last record&amp;nbsp;should not after the check in date of the last record. Consequently, change 15 15 to 14 15 and so on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To summarize, removing one day&amp;nbsp;from the check&amp;nbsp;in date because of the&amp;nbsp;record with check in/out date 16 17&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The record&amp;nbsp;with value of&amp;nbsp; 5 20 (check in/out)&amp;nbsp;will be deleted because of the record after this one (6 6) shows he checked in again&amp;nbsp;before he checked out. The check out date on the 20th most likely be a mistake.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope the explanation makes things clear but not adds confusion. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Dec 2019 23:53:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Clean-date-in-a-longitudinal-data/m-p/613344#M18394</guid>
      <dc:creator>NanZ</dc:creator>
      <dc:date>2019-12-20T23:53:18Z</dc:date>
    </item>
    <item>
      <title>Re: Clean date in a longitudinal data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Clean-date-in-a-longitudinal-data/m-p/613354#M18397</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/304333"&gt;@NanZ&lt;/a&gt;&amp;nbsp; &amp;nbsp;See if this helps?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data HAVE;
input clientid datin datout ;
datalines;
1 1 2
1 2 2
1 3 3
1 4 4
1 5 20
1 6 6
1 9 10
1 11 11
1 12 12
1 13 13
1 14 16
1 15 15
1 16 16
1 16 17
;


data want;
 do _n_=1 by 1 until(last.clientid);
  set have;
  by clientid;
  if datin&amp;lt;_t and _t then _f=1;else _f=0;
  _t=datout;
  datout=datin+1;
  if not _f then output;
 end;
 drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the above seems ok, and still the &lt;STRONG&gt;1 16 17&amp;nbsp;&lt;/STRONG&gt;duplicate bothers you, then the following addresses that piece too&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want;
 if _n_=1 then do;
  dcl hash H () ;
  h.definekey  ("datin","datout") ;
  h.definedata ("datin","datout") ;
  h.definedone () ;
 end; 
 do _n_=1 by 1 until(last.clientid);
  set have;
  by clientid;
  _f= datin&amp;lt;_t and _t;
  _t=datout;
  datout=datin+1;
  if not _f and h.check() ne 0 then output;
  _rc=h.add();
 end;
 h.clear();
 drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Dec 2019 22:18:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Clean-date-in-a-longitudinal-data/m-p/613354#M18397</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-12-20T22:18:19Z</dc:date>
    </item>
    <item>
      <title>Re: Clean date in a longitudinal data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Clean-date-in-a-longitudinal-data/m-p/613369#M18404</link>
      <description>&lt;P&gt;Thanks, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;, for your time and great help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I checked the results generated from your code and found that both deleted record 6 and 12, instead of 5 and 11. I have to check the code on the original data whether the they generate desired results or not. But I would prefer to delete the right one and correct the ones planned, i.e., record 6 and 12.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, the second code deleted one additional record -&amp;nbsp;14.&lt;/P&gt;</description>
      <pubDate>Sat, 21 Dec 2019 00:56:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Clean-date-in-a-longitudinal-data/m-p/613369#M18404</guid>
      <dc:creator>NanZ</dc:creator>
      <dc:date>2019-12-21T00:56:00Z</dc:date>
    </item>
    <item>
      <title>Re: Clean date in a longitudinal data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Clean-date-in-a-longitudinal-data/m-p/613371#M18405</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/304333"&gt;@NanZ&lt;/a&gt;&amp;nbsp;, Thank you for clarifying further and your patience. Please try this and see if this meets ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data HAVE;
input clientid datin datout ;
datalines;
1 1 2
1 2 2
1 3 3
1 4 4
1 5 20
1 6 6
1 9 10
1 11 11
1 12 12
1 13 13
1 14 16
1 15 15
1 16 16
1 16 17
;


data want;
 do _n_=1 by 1 until(last.clientid);
  set have;
  by clientid;
  array t(9999) _temporary_;
  if datin&amp;lt;_t  then t(_n_-1)=1;
  _t=datout;
 end;
 do _n_=1 to _n_;
  set have;
  if t(_n_) then continue;
  datout=datin+1;
  output;
 end;
 call missing(of t(*));
 drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 21 Dec 2019 01:15:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Clean-date-in-a-longitudinal-data/m-p/613371#M18405</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-12-21T01:15:29Z</dc:date>
    </item>
    <item>
      <title>Re: Clean date in a longitudinal data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Clean-date-in-a-longitudinal-data/m-p/613375#M18406</link>
      <description>&lt;P&gt;Thanks, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;, for your great patience too and great help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The newest code deleted the right records, 5 and 11. But the results for the last two records&amp;nbsp;are&amp;nbsp;the same, 16 and 17.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, I am not familiar with array but the data has millions of records.&lt;/P&gt;</description>
      <pubDate>Sat, 21 Dec 2019 02:51:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Clean-date-in-a-longitudinal-data/m-p/613375#M18406</guid>
      <dc:creator>NanZ</dc:creator>
      <dc:date>2019-12-21T02:51:40Z</dc:date>
    </item>
  </channel>
</rss>

