<?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: Best solution to combine room/bed information over period of time... in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Best-solution-to-combine-room-bed-information-over-period-of/m-p/45530#M9417</link>
    <description>If the data is already sorted the way you presented it then you could use the notsorted option in a by statement.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data one;&lt;BR /&gt;
input Visitno Room Bed InDate $ 10-21;&lt;BR /&gt;
cards;&lt;BR /&gt;
1234 1 1 JAN 1, 2011&lt;BR /&gt;
1234 1 1 JAN 2, 2011&lt;BR /&gt;
1234 5 2 JAN 3, 2011&lt;BR /&gt;
1234 5 2 JAN 4, 2011&lt;BR /&gt;
1234 5 2 JAN 5, 2011&lt;BR /&gt;
1234 5 2 JAN 10, 2011&lt;BR /&gt;
1234 1 1 JAN 11, 2011&lt;BR /&gt;
1234 1 1 JAN 12, 2011&lt;BR /&gt;
;;;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data two;&lt;BR /&gt;
set one;&lt;BR /&gt;
retain indt outdt;&lt;BR /&gt;
by room notsorted;&lt;BR /&gt;
if first.room then indt=InDate;&lt;BR /&gt;
else if last.room then do;&lt;BR /&gt;
	outdt=InDate;&lt;BR /&gt;
	output;&lt;BR /&gt;
end;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]</description>
    <pubDate>Thu, 07 Apr 2011 14:02:06 GMT</pubDate>
    <dc:creator>RickM</dc:creator>
    <dc:date>2011-04-07T14:02:06Z</dc:date>
    <item>
      <title>Best solution to combine room/bed information over period of time...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-solution-to-combine-room-bed-information-over-period-of/m-p/45525#M9412</link>
      <description>Hello all;&lt;BR /&gt;
This is more of a strategic question and/or technical one as I have hit a wall on this.&lt;BR /&gt;
&lt;BR /&gt;
In essence I have the following information for example:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Visitno   Room  Bed    InDate&lt;BR /&gt;
1234       1        1        JAN 1, 2011&lt;BR /&gt;
1234       1        1        JAN 2, 2011&lt;BR /&gt;
1234       5        2        JAN 3, 2011&lt;BR /&gt;
1234       5        2        JAN 4, 2011&lt;BR /&gt;
1234       5        2        JAN 5, 2011&lt;BR /&gt;
...&lt;BR /&gt;
1234       5        2        JAN 10, 2011&lt;BR /&gt;
1234       1        1        JAN 11, 2011&lt;BR /&gt;
1234       1        1        JAN 12, 2011&lt;BR /&gt;
&lt;BR /&gt;
I am attempting to compress this information so that it reads:&lt;BR /&gt;
&lt;BR /&gt;
Visitno   Room  Bed    InDate             LastDate&lt;BR /&gt;
1234       1        1        JAN 1, 2011    JAN 2, 2011&lt;BR /&gt;
1234       5        2        JAN 3, 2011    JAN 10, 2011&lt;BR /&gt;
1234       1        1        JAN 11, 2011   JAN 12, 2011&lt;BR /&gt;
&lt;BR /&gt;
I have a program that largely works 99% of the time, but in certain case scenarios (such as above) the same patient ends up back in the same bed in the same room on the same floor if the patient is here long enough and it leads to  erroneous output so that it would read: &lt;BR /&gt;
Visitno   Room  Bed    InDate             LastDate&lt;BR /&gt;
1234       1        1        JAN 1, 2011    JAN 12, 2011&lt;BR /&gt;
1234       5        2        JAN 3, 2011    JAN 10, 2011&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Any guidance would be great!&lt;BR /&gt;
&lt;BR /&gt;
Lawrence</description>
      <pubDate>Wed, 06 Apr 2011 15:30:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-solution-to-combine-room-bed-information-over-period-of/m-p/45525#M9412</guid>
      <dc:creator>_LB</dc:creator>
      <dc:date>2011-04-06T15:30:32Z</dc:date>
    </item>
    <item>
      <title>Re: Best solution to combine room/bed information over period of time...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-solution-to-combine-room-bed-information-over-period-of/m-p/45526#M9413</link>
      <description>Hello ~LB,&lt;BR /&gt;
&lt;BR /&gt;
This is a solution:&lt;BR /&gt;
[pre]&lt;BR /&gt;
data r (rename=(sd=InDate ed=LastDate));&lt;BR /&gt;
  retain Visitno Room Bed sd ed;&lt;BR /&gt;
  set i;&lt;BR /&gt;
  if First.Visitno then sd=InDate;&lt;BR /&gt;
  LAGd=LAG(InDate);&lt;BR /&gt;
  if LAGd ne . and InDate-LAGd &amp;gt; 1 then do; ed=LAGd;   output; sd=InDate; end;&lt;BR /&gt;
  if Last.Visitno                  then do; ed=InDate; output;            end;&lt;BR /&gt;
  by Visitno;&lt;BR /&gt;
  format sd ed date7.;&lt;BR /&gt;
  drop InDate LAGd;&lt;BR /&gt;
run; &lt;BR /&gt;
[/pre]&lt;BR /&gt;
Sincerely,&lt;BR /&gt;
SPR</description>
      <pubDate>Wed, 06 Apr 2011 17:33:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-solution-to-combine-room-bed-information-over-period-of/m-p/45526#M9413</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2011-04-06T17:33:06Z</dc:date>
    </item>
    <item>
      <title>Re: Best solution to combine room/bed information over period of time...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-solution-to-combine-room-bed-information-over-period-of/m-p/45527#M9414</link>
      <description>Thanks SPR-&lt;BR /&gt;
Close, but still at the same place I was before..&lt;BR /&gt;
Ugh!&lt;BR /&gt;
&lt;BR /&gt;
Lawrence</description>
      <pubDate>Wed, 06 Apr 2011 21:59:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-solution-to-combine-room-bed-information-over-period-of/m-p/45527#M9414</guid>
      <dc:creator>_LB</dc:creator>
      <dc:date>2011-04-06T21:59:41Z</dc:date>
    </item>
    <item>
      <title>Re: Best solution to combine room/bed information over period of time...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-solution-to-combine-room-bed-information-over-period-of/m-p/45528#M9415</link>
      <description>Actually .You can make a flag variable to distinguish the obs have the same room and the same bed.try this:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data temp;&lt;BR /&gt;
input Visitno Room Bed InDate &amp;amp; $20.;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1234 1 1 JAN 1, 2011&lt;BR /&gt;
1234 1 1 JAN 2, 2011&lt;BR /&gt;
1234 5 2 JAN 3, 2011&lt;BR /&gt;
1234 5 2 JAN 4, 2011&lt;BR /&gt;
1234 5 2 JAN 5, 2011&lt;BR /&gt;
1234 5 2 JAN 10, 2011&lt;BR /&gt;
1234 1 1 JAN 11, 2011&lt;BR /&gt;
1234 1 1 JAN 12, 2011&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
data temp;&lt;BR /&gt;
 set temp;&lt;BR /&gt;
 if (visitno ne lag(visitno)) or (room ne lag(room) and indate ne lag(indate))&lt;BR /&gt;
   then flag+1;&lt;BR /&gt;
run;&lt;BR /&gt;
data want;&lt;BR /&gt;
 set temp;&lt;BR /&gt;
 by flag;&lt;BR /&gt;
 retain _indate;&lt;BR /&gt;
 if first.flag then _indate=indate;&lt;BR /&gt;
 if last.flag then do;&lt;BR /&gt;
                     lastdat=indate;&lt;BR /&gt;
                     output;&lt;BR /&gt;
                    end;&lt;BR /&gt;
 drop indate flag;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Thu, 07 Apr 2011 07:04:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-solution-to-combine-room-bed-information-over-period-of/m-p/45528#M9415</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-04-07T07:04:34Z</dc:date>
    </item>
    <item>
      <title>Re: Best solution to combine room/bed information over period of time...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-solution-to-combine-room-bed-information-over-period-of/m-p/45529#M9416</link>
      <description>Sorry, Lawrence, I did not realized that you need the following output:&lt;BR /&gt;
Visitno Room Bed InDate LastDate&lt;BR /&gt;
1234 1 1 JAN 1, 2011 JAN 2, 2011&lt;BR /&gt;
1234 5 2 JAN 3, 2011 JAN 10, 2011&lt;BR /&gt;
1234 1 1 JAN 11, 2011 JAN 12, 2011&lt;BR /&gt;
&lt;BR /&gt;
rather then this:&lt;BR /&gt;
Visitno Room Bed InDate LastDate&lt;BR /&gt;
1234 1 1 JAN 1, 2011 JAN 2, 2011&lt;BR /&gt;
1234 5 2 JAN 3, 2011 JAN 10, 2011&lt;BR /&gt;
1234 1 1 JAN 11, 2011 JAN 12, 2011&lt;BR /&gt;
&lt;BR /&gt;
SPR</description>
      <pubDate>Thu, 07 Apr 2011 13:48:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-solution-to-combine-room-bed-information-over-period-of/m-p/45529#M9416</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2011-04-07T13:48:23Z</dc:date>
    </item>
    <item>
      <title>Re: Best solution to combine room/bed information over period of time...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-solution-to-combine-room-bed-information-over-period-of/m-p/45530#M9417</link>
      <description>If the data is already sorted the way you presented it then you could use the notsorted option in a by statement.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data one;&lt;BR /&gt;
input Visitno Room Bed InDate $ 10-21;&lt;BR /&gt;
cards;&lt;BR /&gt;
1234 1 1 JAN 1, 2011&lt;BR /&gt;
1234 1 1 JAN 2, 2011&lt;BR /&gt;
1234 5 2 JAN 3, 2011&lt;BR /&gt;
1234 5 2 JAN 4, 2011&lt;BR /&gt;
1234 5 2 JAN 5, 2011&lt;BR /&gt;
1234 5 2 JAN 10, 2011&lt;BR /&gt;
1234 1 1 JAN 11, 2011&lt;BR /&gt;
1234 1 1 JAN 12, 2011&lt;BR /&gt;
;;;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data two;&lt;BR /&gt;
set one;&lt;BR /&gt;
retain indt outdt;&lt;BR /&gt;
by room notsorted;&lt;BR /&gt;
if first.room then indt=InDate;&lt;BR /&gt;
else if last.room then do;&lt;BR /&gt;
	outdt=InDate;&lt;BR /&gt;
	output;&lt;BR /&gt;
end;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Thu, 07 Apr 2011 14:02:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-solution-to-combine-room-bed-information-over-period-of/m-p/45530#M9417</guid>
      <dc:creator>RickM</dc:creator>
      <dc:date>2011-04-07T14:02:06Z</dc:date>
    </item>
    <item>
      <title>Re: Best solution to combine room/bed information over period of time...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-solution-to-combine-room-bed-information-over-period-of/m-p/45531#M9418</link>
      <description>Hi Lawrence,&lt;BR /&gt;
Try the following:&lt;BR /&gt;
&lt;BR /&gt;
data temp;&lt;BR /&gt;
input Visitno Room Bed InDate &amp;amp; $20.;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1234 1 1 JAN 1, 2011&lt;BR /&gt;
1234 1 1 JAN 2, 2011&lt;BR /&gt;
1234 5 2 JAN 3, 2011&lt;BR /&gt;
1234 5 2 JAN 4, 2011&lt;BR /&gt;
1234 5 2 JAN 5, 2011&lt;BR /&gt;
1234 5 2 JAN 10, 2011&lt;BR /&gt;
1234 1 1 JAN 11, 2011&lt;BR /&gt;
1234 1 1 JAN 12, 2011&lt;BR /&gt;
;&lt;BR /&gt;
data  first last;&lt;BR /&gt;
	set temp;&lt;BR /&gt;
	by room bed indate notsorted;&lt;BR /&gt;
	if first.room = last.room then delete;&lt;BR /&gt;
	if first.room then output first;&lt;BR /&gt;
	if last.room then output last;&lt;BR /&gt;
run;&lt;BR /&gt;
data x;&lt;BR /&gt;
	merge first last(keep = indate rename=(indate = lastdate));&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
Amar Mundankar.</description>
      <pubDate>Tue, 12 Apr 2011 11:44:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-solution-to-combine-room-bed-information-over-period-of/m-p/45531#M9418</guid>
      <dc:creator>AmarMundankar</dc:creator>
      <dc:date>2011-04-12T11:44:27Z</dc:date>
    </item>
    <item>
      <title>Re: Best solution to combine room/bed information over period of time...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-solution-to-combine-room-bed-information-over-period-of/m-p/45532#M9419</link>
      <description>Amar;&lt;BR /&gt;
Your solution works very well! However I did run into one hiccup. I then had to add the unit to the variables and it works 98% of the time but it has the power to skip a unit, &lt;BR /&gt;
&lt;BR /&gt;
below is actual data (with visit # changed). Your program worked perfectly even not including the unit but when it came to line 5 (see the x next to it) this unit/bed was omitted. &lt;BR /&gt;
&lt;BR /&gt;
Also one last level of complexity-the visit no was not included. This will also be integral as there are multiple visit numbers. I should have included a better example. &lt;BR /&gt;
&lt;BR /&gt;
Any additional info/assistance you can provide would be great!&lt;BR /&gt;
Best, &lt;BR /&gt;
&lt;BR /&gt;
Lawrence&lt;BR /&gt;
&lt;BR /&gt;
VISITNO	UNIT	Room	BED	IN_DATE&lt;BR /&gt;
17182355	Z5N	B507	1	9/21/2010&lt;BR /&gt;
17182355	Z5N	B507	1	9/22/2010&lt;BR /&gt;
17182355	Z5N	B507	1	9/23/2010&lt;BR /&gt;
17182355	Z5N	B507	1	9/24/2010&lt;BR /&gt;
17182355	Z4I	A434	K	9/25/2010&lt;BR /&gt;
17182355	Z5N	B507	1	9/26/2010&lt;BR /&gt;
17182355	Z5N	B507	1	9/27/2010&lt;BR /&gt;
17182355	Z5N	B507	1	9/28/2010&lt;BR /&gt;
17182355	Z5N	B507	1	9/29/2010&lt;BR /&gt;
17182355	Z5N	B507	1	10/1/2010&lt;BR /&gt;
17182355	Z5N	B507	1	10/2/2010&lt;BR /&gt;
17182355	Z5N	B507	1	10/3/2010&lt;BR /&gt;
17182355	Z5N	B507	1	10/4/2010&lt;BR /&gt;
17296714	Z5N	B514	1	10/15/2010&lt;BR /&gt;
17296714	Z5N	B514	1	10/16/2010&lt;BR /&gt;
17296714	Z5N	B514	1	10/17/2010&lt;BR /&gt;
17296714	Z5N	B514	1	10/18/2010&lt;BR /&gt;
17296714	Z5N	B514	1	10/19/2010&lt;BR /&gt;
17296714	Z5N	B514	1	10/20/2010&lt;BR /&gt;
17296714	Z5N	B514	1	10/21/2010&lt;BR /&gt;
17296714	Z5N	B514	1	10/22/2010&lt;BR /&gt;
17296714	Z5N	B514	1	10/23/2010&lt;BR /&gt;
17296714	Z5N	B514	1	10/26/2010&lt;BR /&gt;
17296714	Z5N	B514	1	10/27/2010&lt;BR /&gt;
17296714	Z5N	B514	1	10/28/2010&lt;BR /&gt;
17296714	Z5N	B514	1	10/29/2010&lt;BR /&gt;
17296714	Z5N	B514	1	10/30/2010&lt;BR /&gt;
17364770	Z5N	B526	1	11/2/2010&lt;BR /&gt;
17364770	Z5N	B526	1	11/3/2010&lt;BR /&gt;
17364770	Z5N	B526	1	11/4/2010&lt;BR /&gt;
17364770	Z5N	B526	1	11/5/2010&lt;BR /&gt;
17501920	Z4E	428	A	12/3/2010&lt;BR /&gt;
17501920	Z4E	428	A	12/4/2010&lt;BR /&gt;
17501920	Z5N	B507	1	12/5/2010&lt;BR /&gt;
17501920	Z5N	B507	1	12/6/2010&lt;BR /&gt;
17501920	Z5N	B507	1	12/7/2010&lt;BR /&gt;
17501920	Z5N	B507	1	12/8/2010&lt;BR /&gt;
17621708	Z5N	B528	1	1/5/2011&lt;BR /&gt;
17621708	Z5N	B528	1	1/6/2011&lt;BR /&gt;
17621708	Z5N	B528	1	1/7/2011&lt;BR /&gt;
17621708	Z5N	B528	1	1/8/2011&lt;BR /&gt;
17621708	Z5N	B528	1	1/9/2011&lt;BR /&gt;
17621708	Z5N	B528	1	1/10/2011&lt;BR /&gt;
17621708	Z5N	B528	1	1/11/2011&lt;BR /&gt;
17621708	Z5N	B528	1	1/12/2011&lt;BR /&gt;
17676853	Z4I	A434	C	1/17/2011&lt;BR /&gt;
17676853	Z4I	A434	C	1/18/2011&lt;BR /&gt;
17676853	Z5N	B516	1	1/19/2011&lt;BR /&gt;
17676853	Z5N	B516	1	1/20/2011&lt;BR /&gt;
17676853	Z5N	B516	1	1/21/2011&lt;BR /&gt;
17676853	Z5N	B516	1	1/22/2011&lt;BR /&gt;
17676853	Z5N	B516	1	1/23/2011&lt;BR /&gt;
17676853	Z5N	B516	1	1/24/2011&lt;BR /&gt;
17676853	Z5N	B516	1	1/25/2011&lt;BR /&gt;
17676853	Z5N	B516	1	1/26/2011&lt;BR /&gt;
17676853	Z5N	B516	1	1/27/2011&lt;BR /&gt;
17676853	Z5N	B516	1	1/28/2011&lt;BR /&gt;
17676853	Z5N	B516	1	1/29/2011&lt;BR /&gt;
17676853	Z5N	B516	1	1/30/2011&lt;BR /&gt;
17676853	Z5N	B516	1	1/31/2011&lt;BR /&gt;
17676853	Z4I	A434	C	2/1/2011&lt;BR /&gt;
17676853	Z4I	A434	C	2/2/2011&lt;BR /&gt;
17676853	Z5N	B529	2	2/3/2011&lt;BR /&gt;
17676853	Z5N	B529	2	2/4/2011&lt;BR /&gt;
17676853	Z5N	B529	2	2/5/2011&lt;BR /&gt;
17676853	Z5N	B529	2	2/6/2011&lt;BR /&gt;
17676853	Z5N	B529	2	2/7/2011&lt;BR /&gt;
17676853	Z5N	B529	2	2/8/2011&lt;BR /&gt;
17676853	Z5N	B529	2	2/9/2011&lt;BR /&gt;
17676853	Z5N	B529	2	2/10/2011&lt;BR /&gt;
17676853	Z5N	B529	2	2/11/2011&lt;BR /&gt;
17676853	Z5N	B529	2	2/12/2011&lt;BR /&gt;
17676853	Z5N	B529	2	2/13/2011&lt;BR /&gt;
17676853	Z5N	B529	2	2/14/2011&lt;BR /&gt;
17676853	Z5N	B529	2	2/15/2011&lt;BR /&gt;
17676853	Z5N	B529	2	2/16/2011&lt;BR /&gt;
17676853	Z5N	B529	2	2/17/2011&lt;BR /&gt;
17676853	Z5N	B529	2	2/18/2011</description>
      <pubDate>Wed, 13 Apr 2011 21:00:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-solution-to-combine-room-bed-information-over-period-of/m-p/45532#M9419</guid>
      <dc:creator>_LB</dc:creator>
      <dc:date>2011-04-13T21:00:27Z</dc:date>
    </item>
    <item>
      <title>Re: Best solution to combine room/bed information over period of time...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-solution-to-combine-room-bed-information-over-period-of/m-p/45533#M9420</link>
      <description>Amar;&lt;BR /&gt;
I figured it out. by removing the if first.room = last.room then delete statement I got the missing unit back..&lt;BR /&gt;
&lt;BR /&gt;
Thanks again! &lt;BR /&gt;
&lt;BR /&gt;
Lawrence</description>
      <pubDate>Wed, 13 Apr 2011 21:22:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-solution-to-combine-room-bed-information-over-period-of/m-p/45533#M9420</guid>
      <dc:creator>_LB</dc:creator>
      <dc:date>2011-04-13T21:22:11Z</dc:date>
    </item>
  </channel>
</rss>

