In sas 9.4 i have a dataset looking something like this: id startdate enddate indate outdate owner 498106 22.01.2019 09.11.2019 29.01.2018 . 803 498106 22.01.2019 09.11.2019 01.01.2019 26.05.2023 584 499547 23.01.2019 09.11.2019 13.02.2018 . 803 499547 23.01.2019 09.11.2019 01.01.2019 . 584 where . is missing outdate. I want to manipulate this in two ways: 1. In cases where the outdate is missing, and it is not the last id record, I want to use the indate for the record after as the outdate. 2. In cases where the the outdate is missing, and it is the last record for that id, i want to put 09.11.2023. The code should produce this dataset: animal_id startdate enddate indate outdate owner 498106 22.01.2019 09.11.2019 29.01.2018 01.01.2019 803 498106 22.01.2019 09.11.2019 01.01.2019 26.05.2023 584 499547 23.01.2019 09.11.2019 13.02.2018 01.01.2019 803 499547 23.01.2019 09.11.2019 01.01.2019 09.11.2023 584 Note that id's can have more that two rows each in the real dataset. So far I have this code, proc sort data=have; by id indate outdate; run;
data want;
set have;
by id indate outdate;
if id = lag(id) and lag(outdate) = . then outdate2 = indate;
if last.id and outdate = . then outdate = 23323;
run;
which produce the acquired results for problem 2, and store the correct indate for use in problem 1, but I do not know how to insert it in the row above. Any help is appreciated.
... View more