If the data is already sorted the way you presented it then you could use the notsorted option in a by statement.
[pre]
data one;
input Visitno Room Bed InDate $ 10-21;
cards;
1234 1 1 JAN 1, 2011
1234 1 1 JAN 2, 2011
1234 5 2 JAN 3, 2011
1234 5 2 JAN 4, 2011
1234 5 2 JAN 5, 2011
1234 5 2 JAN 10, 2011
1234 1 1 JAN 11, 2011
1234 1 1 JAN 12, 2011
;;;
run;
data two;
set one;
retain indt outdt;
by room notsorted;
if first.room then indt=InDate;
else if last.room then do;
outdt=InDate;
output;
end;
run;
[/pre]
... View more