Hello everyone,
I have a table which indicates me for every ID the number of events happened at a specific time. The number of the events indicate me for many monh the event was active and also when it started. So in my table have2 for example I see for ID=1 that the event occured first in November 2020 at lastest for 2 months (November+December), for ID=2 it started in January 2021 and only lasted 1 month etc.
data have;
input id date: date9. number;
format date date9.;
datalines;
1 01JAN2021 2
2 01FEB2021 1
3 01JUN2021 3
;
run;
data have2; set have; format start_month MONYY.; start_month=intnx("month",date,-number); run;
My goal is to have for every ID, starting with the first month the event occured, an entry of 0 or 1 which indicates me, if for that month the event was active or not. The idea is to have the table recreated every month based on the information provided in the have table and include another mohthly entry either with 0 or 1.
So to have a table like this:
ID
Month
flag
1
01.11.2020
1
1
01.12.2020
1
1
01.01.2021
0
1
01.02.2021
0
1
01.03.2021
0
1
01.04.2021
0
1
01.05.2021
0
1
01.06.2021
0
2
01.01.2021
1
2
01.02.2021
0
2
01.03.2021
0
2
01.04.2021
0
2
01.05.2021
0
2
01.06.2021
0
3
01.03.2021
1
3
01.04.2021
1
3
01.05.2021
1
3
01.06.2021
0
Maybe some of you have a good idea, how to solve that.
Thank you.
... View more