<?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 consolidate these records? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-consolidate-these-records/m-p/292343#M311737</link>
    <description>&lt;P&gt;Do Until() can be useful for this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Member_ID   (Eff_Date   Term_Date) (:yymmdd.)   Sequence_ID;
format eff_date term_date yymmdd10.;
datalines;
123456789   2005-01-01   2006-01-31   1
123456789   2006-02-01   2007-02-14   2
123456789   2007-02-15   2007-05-11   3
123456789   2007-05-12   2008-02-28   4
123456789   2008-02-29   2008-12-31   5
123456789   2009-11-01   2009-12-31   6
123456789   2010-01-01   2010-08-11   7
123456789   2010-08-12   2017-12-31   8
;

data want;
do until(last.member_id);
    set have; by member_id;
    if first.member_id then do;
        e_date = eff_date;
        end;
    else if intnx("DAY", eff_date, -1) ne next_date then do;
        t_date = next_date;
        s_id = sum(s_id, 1);
        output;
        e_date = eff_date;
        end;
    next_date = term_date;
    end;
t_date = term_date;
s_id = sum(s_id, 1);
output;

format e_date t_date yymmdd10.;
keep member_id e_date t_date s_id;
rename e_date=eff_date t_date=term_date s_id=sequence_id;
run;

proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 18 Aug 2016 03:45:48 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2016-08-18T03:45:48Z</dc:date>
    <item>
      <title>How to consolidate these records?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-consolidate-these-records/m-p/292218#M311734</link>
      <description>&lt;P&gt;I need to consolidate one member’s multiple records with consecutive dates into one. That is, one member has multiple records with the start date of one records being the next day of the previous record’s end date. &amp;nbsp;Here is one example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Member_ID &amp;nbsp; Eff_Date &amp;nbsp; Term_Date &amp;nbsp; Sequence_ID&lt;BR /&gt;--------- ---------- ---------- --------------------&lt;BR /&gt;123456789 &amp;nbsp; 2005-01-01 &amp;nbsp; 2006-01-31 &amp;nbsp; 1&lt;BR /&gt;123456789 &amp;nbsp; 2006-02-01 &amp;nbsp; 2007-02-14 &amp;nbsp; 2&lt;BR /&gt;123456789 &amp;nbsp; 2007-02-15 &amp;nbsp; 2007-05-11 &amp;nbsp; 3&lt;BR /&gt;123456789 &amp;nbsp; 2007-05-12 &amp;nbsp; 2008-02-28 &amp;nbsp; 4&lt;BR /&gt;123456789 &amp;nbsp; 2008-02-29 &amp;nbsp; 2008-12-31 &amp;nbsp; 5&lt;BR /&gt;123456789 &amp;nbsp; 2009-11-01 &amp;nbsp; 2009-12-31 &amp;nbsp; 6&lt;BR /&gt;123456789 &amp;nbsp; 2010-01-01 &amp;nbsp; 2010-08-11 &amp;nbsp; 7&lt;BR /&gt;123456789 &amp;nbsp; 2010-08-12 &amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&lt;SPAN&gt;2017-12-31&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;8&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The end result I'm looking for would be two records for this member like this.&lt;BR /&gt;&lt;BR /&gt;Member_ID &amp;nbsp; Eff_Date &amp;nbsp; Term_Date &amp;nbsp; Sequence_ID&lt;BR /&gt;--------- ---------- ---------- --------------------&lt;BR /&gt;123456789 &amp;nbsp; 2005-01-01 &amp;nbsp; 2008-12-31&amp;nbsp;&amp;nbsp; 1&lt;BR /&gt;123456789 &amp;nbsp; 2009-11-01 &amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&lt;SPAN&gt;2017-12-31&lt;/SPAN&gt;&lt;/SPAN&gt;&amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea about how to deal with this in SAS?&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2016 15:42:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-consolidate-these-records/m-p/292218#M311734</guid>
      <dc:creator>jcg2000</dc:creator>
      <dc:date>2016-08-17T15:42:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to consolidate these records?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-consolidate-these-records/m-p/292237#M311735</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have (
  drop=sequence_id
  rename=(
    member_id=id
    eff_date=eff
    term_date=term
  )
) end=done;
by id;
retain eff_date term_date sequence_id;
format eff_date term_date yymmddd10.;
if first.id
then do;
  if member_id ne . /* we had a previous member_id that is through now */
  then output;
  eff_date = eff;
  term_date = term;
  sequence_id = 1;
  member_id = id;
end;
if term_date + 1 &amp;lt; eff /* start a new sequence */
then do;
  output; /* write the old sequence */
  member_id = id;
  eff_date = eff;
  sequence_id + 1;
end;
term_date = term;
if done then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(Untested)&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2016 17:36:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-consolidate-these-records/m-p/292237#M311735</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-08-17T17:36:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to consolidate these records?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-consolidate-these-records/m-p/292336#M311736</link>
      <description>&lt;PRE&gt;
data have;
input Member_ID   Eff_Date  : yymmdd10. Term_Date : yymmdd10. Sequence_ID;
format Eff_Date Term_Date  yymmdd10.;
cards;
123456789   2005-01-01   2006-01-31   1
123456789   2006-02-01   2007-02-14   2
123456789   2007-02-15   2007-05-11   3
123456789   2007-05-12   2008-02-28   4
123456789   2008-02-29   2008-12-31   5
123456789   2009-11-01   2009-12-31   6
123456789   2010-01-01   2010-08-11   7
123456789   2010-08-12   2017-12-31   8
;
run;

data temp;
 set have;
 by Member_ID;
 if first.Member_ID or Eff_Date ne lag(Term_Date)+1 then group+1;
run;
data want;
 set temp;
 by group;
 retain start ;
 if first.group then start=Eff_Date;
 if last.group then do;
  new_id+1;end=Term_Date;output;
 end;
 format start end yymmdd10.;
 keep Member_ID start end new_id;
run;


&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Aug 2016 02:46:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-consolidate-these-records/m-p/292336#M311736</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-08-18T02:46:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to consolidate these records?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-consolidate-these-records/m-p/292343#M311737</link>
      <description>&lt;P&gt;Do Until() can be useful for this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Member_ID   (Eff_Date   Term_Date) (:yymmdd.)   Sequence_ID;
format eff_date term_date yymmdd10.;
datalines;
123456789   2005-01-01   2006-01-31   1
123456789   2006-02-01   2007-02-14   2
123456789   2007-02-15   2007-05-11   3
123456789   2007-05-12   2008-02-28   4
123456789   2008-02-29   2008-12-31   5
123456789   2009-11-01   2009-12-31   6
123456789   2010-01-01   2010-08-11   7
123456789   2010-08-12   2017-12-31   8
;

data want;
do until(last.member_id);
    set have; by member_id;
    if first.member_id then do;
        e_date = eff_date;
        end;
    else if intnx("DAY", eff_date, -1) ne next_date then do;
        t_date = next_date;
        s_id = sum(s_id, 1);
        output;
        e_date = eff_date;
        end;
    next_date = term_date;
    end;
t_date = term_date;
s_id = sum(s_id, 1);
output;

format e_date t_date yymmdd10.;
keep member_id e_date t_date s_id;
rename e_date=eff_date t_date=term_date s_id=sequence_id;
run;

proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Aug 2016 03:45:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-consolidate-these-records/m-p/292343#M311737</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-08-18T03:45:48Z</dc:date>
    </item>
  </channel>
</rss>

