<?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 combine data from multiple rows into a single row based on conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-data-from-multiple-rows-into-a-single-row-based/m-p/975672#M378140</link>
    <description>&lt;P&gt;Hi Quentin,&lt;/P&gt;&lt;P&gt;Thanks for the response. I would leave them separate. Only consecutive visits within same facility need to be collapsed.&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;</description>
    <pubDate>Wed, 24 Sep 2025 15:57:32 GMT</pubDate>
    <dc:creator>arorata</dc:creator>
    <dc:date>2025-09-24T15:57:32Z</dc:date>
    <item>
      <title>How to combine data from multiple rows into a single row based on conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-data-from-multiple-rows-into-a-single-row-based/m-p/975603#M378130</link>
      <description>&lt;P&gt;Hi have the following data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data have;
	input id$ facility$  start end;
	length id facility $1 start end 4.;
	informat start end date9.;
	format start end mmddyy10.;
	datalines;
	1 A 01jan2010 31jan2010
	1 A 01mar2010 31mar2010
	1 A 01apr2010 30apr2010
	1 A 15jun2010 30jun2010
	1 B 15jul2010 31aug2010
	1 B 01nov2010 31dec2010
	1 B 31jan2011 01mar2011
	1 B 03mar2011 31aug2011
	1 A 01sep2011 31oct2011
	1 A 01dec2011 31dec2011
	;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I would like to be able to combine all rows into a single row &lt;STRONG&gt;within a facility&lt;/STRONG&gt; if difference between start date of current row and end date of previous row is &lt;STRONG&gt;=&amp;lt; 31.&lt;/STRONG&gt; So the new start date would be the start date of earliest of combined rows and end date would be the end date of last row &lt;STRONG&gt;within&lt;/STRONG&gt; &lt;STRONG&gt;a facility&lt;/STRONG&gt;.&amp;nbsp; The data I want looks like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;Facility&lt;/TD&gt;&lt;TD&gt;Start&lt;/TD&gt;&lt;TD&gt;End&lt;/TD&gt;&lt;TD&gt;Comment&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;&lt;CODE class=""&gt;01jan2010&lt;/CODE&gt;&lt;/TD&gt;&lt;TD&gt;&lt;CODE class=""&gt;30apr2010&lt;/CODE&gt;&lt;/TD&gt;&lt;TD&gt;Combines rows 1-3 as gap between current start date and previous end date =&amp;lt; 31 days&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;&lt;CODE class=""&gt;15jun2010&lt;/CODE&gt;&lt;/TD&gt;&lt;TD&gt;&lt;CODE class=""&gt;30jun2010&lt;/CODE&gt;&lt;/TD&gt;&lt;TD&gt;New row&amp;nbsp;as gap between current start date and previous end date &amp;gt; 31 days&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;&lt;CODE class=""&gt;15jul2010&lt;/CODE&gt;&lt;/TD&gt;&lt;TD&gt;&lt;CODE class=""&gt;31aug2010&lt;/CODE&gt;&lt;/TD&gt;&lt;TD&gt;New row as facility changes even if gap condition is satisfied&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;&lt;CODE class=""&gt;01nov2010&lt;/CODE&gt;&lt;/TD&gt;&lt;TD&gt;&lt;CODE class=""&gt;31aug2011&lt;/CODE&gt;&lt;/TD&gt;&lt;TD&gt;New row even if same facility as previous one but the gap is &amp;gt; 31 days&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;&lt;CODE class=""&gt;01sep2011&lt;/CODE&gt;&lt;/TD&gt;&lt;TD&gt;&lt;CODE class=""&gt;31dec2011&lt;/CODE&gt;&lt;/TD&gt;&lt;TD&gt;Rows 9-10 combined as they are within same facility and gape between start date of row 10 and end date of row 9 is =&amp;lt; 31 days&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Original data has ~400 million records and is sorted by ID and START but not by FACILITY. I would prefer to avoid resorting and merging. Records from one ID should not be retained into a different ID. Any suggestion are highly appreciated. Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 23 Sep 2025 19:26:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-data-from-multiple-rows-into-a-single-row-based/m-p/975603#M378130</guid>
      <dc:creator>arorata</dc:creator>
      <dc:date>2025-09-23T19:26:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine data from multiple rows into a single row based on conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-data-from-multiple-rows-into-a-single-row-based/m-p/975624#M378132</link>
      <description>&lt;P&gt;Some kind of sort operation is needed, regardless of technique chosen.&lt;/P&gt;
&lt;P&gt;I would go for the approach of having the data sorted by id (assume facilities within each id is what you are looking for), facility and start date.&lt;/P&gt;
&lt;P&gt;Then use REATAIN for two new variables to keep your start and and dates across observations.&lt;/P&gt;
&lt;P&gt;And then an explicit OUTPUT when the gap is greater than 31 days or your reach an new id/facility combination.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Sep 2025 06:04:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-data-from-multiple-rows-into-a-single-row-based/m-p/975624#M378132</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2025-09-24T06:04:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine data from multiple rows into a single row based on conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-data-from-multiple-rows-into-a-single-row-based/m-p/975632#M378133</link>
      <description>&lt;P&gt;I think This question is more complicated than you can expected.&lt;/P&gt;
&lt;P&gt;Anyway ,the following code could give you a good start.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input id$ facility$  start end;
	length id facility $1 start end 4.;
	informat start end date9.;
	format start end mmddyy10.;
	datalines;
	1 A 01jan2010 31jan2010
	1 A 01mar2010 31mar2010
	1 A 01apr2010 30apr2010
	1 A 15jun2010 30jun2010
	1 B 15jul2010 31aug2010
	1 B 01nov2010 31dec2010
	1 B 31jan2011 01mar2011
	1 B 03mar2011 31aug2011
	1 A 01sep2011 31oct2011
	1 A 01dec2011 31dec2011
	;
run;
data temp;
 set have;
 do date=start to end;
  output;
 end;
 format date date9.;
 keep id facility date;
run;
proc sort data=temp nodupkey;
by id date;
run;

data temp2;
 set temp;
 by id facility notsorted;
 if first.facility or dif(date)&amp;gt;31 then group+1;
run;

proc sql;
create table want as
select group,min(id) as id,min(facility) as facility,
   min(date) as start format=date9.,max(date) as end format=date9.
    from temp2
	 group by group;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Sep 2025 08:08:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-data-from-multiple-rows-into-a-single-row-based/m-p/975632#M378133</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-09-24T08:08:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine data from multiple rows into a single row based on conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-data-from-multiple-rows-into-a-single-row-based/m-p/975649#M378134</link>
      <description>&lt;P&gt;If there were two visits to facility A within 31 days of each other, but there was a visit to facility B in between, would you want to collapse the two visits to A? or leave them as separate?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thinking of data like:&lt;/P&gt;
&lt;PRE&gt;  1 A 01jan2010 31jan2010
  1 B 01feb2010 07feb2010
  1 A 08feb2010 28feb2010&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Sep 2025 12:24:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-data-from-multiple-rows-into-a-single-row-based/m-p/975649#M378134</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2025-09-24T12:24:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine data from multiple rows into a single row based on conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-data-from-multiple-rows-into-a-single-row-based/m-p/975653#M378135</link>
      <description>&lt;P&gt;So assuming you do not want to collapse stays that use multiple facilities you can use the NOTSORTED keyword on the BY statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First let's setup the example data and make sure it sorted as you indicated.&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	length id facility $1 start end 4;
	input id facility start end;
	informat start end date.;
	format start end yymmdd10.;
datalines;
1 A 01jan2010 31jan2010
1 A 01mar2010 31mar2010
1 A 01apr2010 30apr2010
1 A 15jun2010 30jun2010
1 B 15jul2010 31aug2010
1 B 01nov2010 31dec2010
1 B 31jan2011 01mar2011
1 B 03mar2011 31aug2011
1 A 01sep2011 31oct2011
1 A 01dec2011 31dec2011
;

proc sort; by id start ; run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;
&lt;P&gt;Let's but the GAP value into a macro variable so we can more easily change it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let gap=31 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now just process the data by ID and FACILITY.&amp;nbsp; Remember the first start and latest end and output a record when you hit a gap or the last record in the facility.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data stays;
 do until(last.facility);
   set have;
   by id facility notsorted ;
   length stay first_start last_stop 4 ;
   format first_start last_stop yymmdd10.;
   if first.facility then link next;
   else if start &amp;gt; (last_stop + &amp;amp;gap) then do;
      output;
      link next;
   end;
   else last_stop=end;
  end;
  output;
return;
next:
  stay=sum(stay,1);
  first_start=start; 
  last_stop=end ; 
return;
  drop start end ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1758718980871.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/110123iBCDE47EC214CCEC5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1758718980871.png" alt="Tom_0-1758718980871.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_1-1758719000314.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/110124iF9BDCF3CCD5177A0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_1-1758719000314.png" alt="Tom_1-1758719000314.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;If you set the allowed GAP to only 15 days then will find more distinct stays.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1758720244225.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/110125i77A6C72E305E872F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1758720244225.png" alt="Tom_0-1758720244225.png" /&gt;&lt;/span&gt;&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;</description>
      <pubDate>Wed, 24 Sep 2025 13:24:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-data-from-multiple-rows-into-a-single-row-based/m-p/975653#M378135</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-09-24T13:24:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine data from multiple rows into a single row based on conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-data-from-multiple-rows-into-a-single-row-based/m-p/975669#M378138</link>
      <description>&lt;P&gt;Hi LinusH,&lt;/P&gt;&lt;P&gt;Thanks for responding. As I mentioned in my original question, I would strongly prefer a solution without needing another sort on the data. It is already sorted by ID and start date. Original dataset has about 400 million records and 100s of columns.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Sep 2025 15:45:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-data-from-multiple-rows-into-a-single-row-based/m-p/975669#M378138</guid>
      <dc:creator>arorata</dc:creator>
      <dc:date>2025-09-24T15:45:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine data from multiple rows into a single row based on conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-data-from-multiple-rows-into-a-single-row-based/m-p/975671#M378139</link>
      <description>&lt;P&gt;Hi Ksharp,&lt;/P&gt;&lt;P&gt;Thanks for your suggestion. I think this could work but as I mentioned in my original post that the actual dataset has about 400 million rows and 100+ columns. Each data step takes 7-9 hours depending on complexity. I was thinking it could be done if there was a lead() like function where you could load the value of facility into current row from the subsequent row, it could in combination with lag() to compute gap could achieve what I want.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Arorata&lt;/P&gt;</description>
      <pubDate>Wed, 24 Sep 2025 15:54:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-data-from-multiple-rows-into-a-single-row-based/m-p/975671#M378139</guid>
      <dc:creator>arorata</dc:creator>
      <dc:date>2025-09-24T15:54:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine data from multiple rows into a single row based on conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-data-from-multiple-rows-into-a-single-row-based/m-p/975672#M378140</link>
      <description>&lt;P&gt;Hi Quentin,&lt;/P&gt;&lt;P&gt;Thanks for the response. I would leave them separate. Only consecutive visits within same facility need to be collapsed.&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;</description>
      <pubDate>Wed, 24 Sep 2025 15:57:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-data-from-multiple-rows-into-a-single-row-based/m-p/975672#M378140</guid>
      <dc:creator>arorata</dc:creator>
      <dc:date>2025-09-24T15:57:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine data from multiple rows into a single row based on conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-data-from-multiple-rows-into-a-single-row-based/m-p/975674#M378141</link>
      <description>&lt;P&gt;Not sure what you plan to do with the values of those other hundred variables, but it you need to keep the values from the final observation for a group then using "lead" might be what you need.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In that case use two SET statements with the second one offset by one.&lt;/P&gt;
&lt;P&gt;Let's add a ROW variable to simulate what would happen to those auxiliary variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have ;
  by id facility notsorted;
  row+1;
  set have(firstobs=2 keep=start rename=(start=next_start)) have(obs=1 drop=_all_);
  if first.facility then first_start=start;
  format first_start yymmdd10.;
  retain first_start ;
  if not last.facility then gap=next_start-end;
  if (gap&amp;gt;31) or last.facility then do;
    start=first_start;
    output;
    first_start=next_start;
  end;
  drop first_start next_start;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Result&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1758732308365.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/110129i6669917630A57236/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1758732308365.png" alt="Tom_0-1758732308365.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Sep 2025 16:45:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-data-from-multiple-rows-into-a-single-row-based/m-p/975674#M378141</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-09-24T16:45:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine data from multiple rows into a single row based on conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-data-from-multiple-rows-into-a-single-row-based/m-p/975675#M378142</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;
&lt;P&gt;Thanks for your suggestion. I think this will work for me with very minor tweaks. I will mark this as a solution.&lt;/P&gt;
&lt;P&gt;Kind regards,&lt;/P&gt;</description>
      <pubDate>Wed, 24 Sep 2025 17:00:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-data-from-multiple-rows-into-a-single-row-based/m-p/975675#M378142</guid>
      <dc:creator>arorata</dc:creator>
      <dc:date>2025-09-24T17:00:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine data from multiple rows into a single row based on conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-data-from-multiple-rows-into-a-single-row-based/m-p/975676#M378143</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;
&lt;P&gt;I just mentioned the number of columns because some of the solutions suggested resorting the original dataset or using multiple data steps, which I wanted to avoid given the huge size. You are correct that I do not need the last values for other variables so your original solution works for me. Just out of curiosity, does having two set statements offsetting by a row in order to "look into the future" have almost double the overhead in terms of computation time compared to the usual single set statement commonly used?&lt;/P&gt;
&lt;P&gt;Kind regards,&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Sep 2025 17:06:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-data-from-multiple-rows-into-a-single-row-based/m-p/975676#M378143</guid>
      <dc:creator>arorata</dc:creator>
      <dc:date>2025-09-24T17:06:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine data from multiple rows into a single row based on conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-data-from-multiple-rows-into-a-single-row-based/m-p/975677#M378144</link>
      <description>&lt;P&gt;No, because both SAS and your operating system will cache the file.&amp;nbsp; So the second SET will get its observation from the cache most of the time.&amp;nbsp; And when it doesn't the the next time the first SET runs it will find the observation in the cache.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Sep 2025 17:15:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-data-from-multiple-rows-into-a-single-row-based/m-p/975677#M378144</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-09-24T17:15:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine data from multiple rows into a single row based on conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-data-from-multiple-rows-into-a-single-row-based/m-p/975680#M378145</link>
      <description>&lt;P&gt;Thanks for answering that. Much appreciated.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Sep 2025 17:31:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-data-from-multiple-rows-into-a-single-row-based/m-p/975680#M378145</guid>
      <dc:creator>arorata</dc:creator>
      <dc:date>2025-09-24T17:31:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine data from multiple rows into a single row based on conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-data-from-multiple-rows-into-a-single-row-based/m-p/975710#M378153</link>
      <description>&lt;P&gt;If your data looks like so clear as what you posted, that would be very easy.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input id$ facility$  start end;
	length id facility $ 8;
	informat start end date9.;
	format start end mmddyy10.;
	datalines;
	1 A 01jan2010 31jan2010
	1 A 01mar2010 31mar2010
	1 A 01apr2010 30apr2010
	1 A 15jun2010 30jun2010
	1 B 15jul2010 31aug2010
	1 B 01nov2010 31dec2010
	1 B 31jan2011 01mar2011
	1 B 03mar2011 31aug2011
	1 A 01sep2011 31oct2011
	1 A 01dec2011 31dec2011
	;
run;
data temp;
 set have;
 by id facility notsorted;
 if first.facility or (start-lag(end))&amp;gt;31 then _group+1;
run;
data want;
set temp(rename=(start=_start));
by _group;
retain start .;
if first._group then start=_start;
if last._group;
drop _group _start;
format end start date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Sep 2025 07:05:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-data-from-multiple-rows-into-a-single-row-based/m-p/975710#M378153</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-09-25T07:05:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine data from multiple rows into a single row based on conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-data-from-multiple-rows-into-a-single-row-based/m-p/975739#M378158</link>
      <description>Hi Ksharp,&lt;BR /&gt;Thanks for the program. It works. If I could I would mark this too as a solution. Appreciate the help.&lt;BR /&gt;Kind regards,</description>
      <pubDate>Thu, 25 Sep 2025 15:31:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-data-from-multiple-rows-into-a-single-row-based/m-p/975739#M378158</guid>
      <dc:creator>arorata</dc:creator>
      <dc:date>2025-09-25T15:31:50Z</dc:date>
    </item>
  </channel>
</rss>

