Hello, I have a listing of patients and their dates of admits and releases by facility type. For example, patient 1 has four lines. He was in facility A from 09OCT23 - 22DEC23 then facility B continuously from 23JUL24 - . (current). I would like in my final table to have only 2 lines for patient 1: admit=09OCT23 - release=22DEC23 and admit=30AUG24 - release=. I only care about the admits for facility A, BUT if he was in facility A and was transferred to facility B in a continous time series, I want the last release date in the series, regadless of the facility. In this scenario, he started on 23JUL24 in facility B and ended in facility A but I only want the facility A date range admit=30AUG24 and release=. Please help, I tried with retain, with LAG... but without success... Thank you. my initial table: id facility amit release 1 A 09OCT23 22DEC23 1 B 23JUL24 27AUG24 1 B 27AUG24 30AUG24 1 A 30AUG24 . 2 A 15DEC23 14JAN24 2 B 14JAN24 22JAN24 2 A 22JAN24 08MAR24 and my final table would be: id facility admit release 1 A 09OCT23 22DEC23 1 A 30AUG24 . 2 A 15DEC23 08MAR24 Here's what I tried: proc sort data=DELETE; by id admit;
data TEST (drop=_:);
do until ((release+1 < _next_admit) or last.juvnum=1);
set DELETE;
by id admit;
merge DELETE DELETE (firstobs=2 keep=admit rename=(admit=_next_admit));
_min_admit=min(_min_admit,admit);
if release=. and last.admit=0 then release=_next_admit-1;
end;
admit=_min_admit;
run; But, with this code, I get this. The first record is okay, but the second line starts with the admit of facility B and I only want facility A admits and then the release date is that of the next id admit. id facility admit release 1 A 09OCT23 22DEC23 1 A 23JUL24 15DEC23 2 A 15DEC23 08MAR24 Thank you in advance!
... View more