is there a way to count how many days pass from a start-end to the next one? Let say:
ID Start End 0001 22JAN2022 23JAN2022 0001 26JAN2022 30JAN2022 0001 03MAR2022 08MAR2022 0001 09MAR2022 15MAR2022 0001 17MAR2022 30MAR2022
desired output:
ID Start End days 0001 22JAN2022 23JAN2022 3 0001 26JAN2022 30JAN2022 4 0001 03FEB2022 08MAR2022 1 0001 09MAR2022 15MAR2022 2 0001 17MAR2022 30MAR2022 .......
>Solution :
I believe I demonstrated this in another thread but there you go
data have;
input ID $ (Start End)(:date9.);
format Start End date9.;
datalines;
0001 22JAN2022 23JAN2022
0001 26JAN2022 30JAN2022
0001 03FEB2022 08MAR2022
0001 09MAR2022 15MAR2022
0001 17MAR2022 30MAR2022
;
data want;
set have;
by ID;
set have(firstobs = 2 rename = start = s keep = start)
have(obs = 1 drop = _all_);
if last.ID then s = .;
days = s - end;
run;