Hi, I have a dataset like the following. data my_data;
input appno id movement_date Date9. movement_indicator $;
format movement_date Date9. ;
datalines;
1 10 21JUN2023 A
1 10 19JUL2023 D
2 20 01DEC2022 A
2 20 04APR2023 D
2 20 16JUN2023 A
2 20 26NOV2023 D
4 20 28DEC2022 A
4 20 18MAR2023 D
4 50 28DEC2022 A
4 50 18MAR2023 D
6 60 17APR2023 D
7 70 27JUL2023 A
8 80 27NOV2022 D
8 80 27MAR2023 A
8 80 27JUL2023 D
;
run; Arrivals are marked as 'A' and departures are 'D'. I want to calculate the time spent by each appno and id. I just want to disregard any single arrivals, and single departures. Also, if the first movement is a departure in any group they should also be ignored. The following is what I tried. But, still struglling to remove single departures and first departures. data want(drop=LAG);
format LAG DATETIME24.;
set my_data;
LAG=LAG(movement_date);
by appno id;
if movement_indicator = 'A' then dif=0;
if movement_indicator = 'D' then dif=intCK("days",LAG,movement_date);
run; Thanks.
... View more