Hi, I have data as follows
data have;
input subject studyday visit trt_changeday ;
datalines;
1 23 1 30
1 36 2 30
1 40 3 30
1 55 4 30
1 78 5 30
2 23 1 35
2 25 2 35
2 44 3 35
3 12 1 24
3 18 2 24
3 30 3 24
3 45 4 24
3 66 5 24
4 2 1 47
4 56 2 47
4 89 3 47
;
run;
data have;
set have;
gap=trt_changeday-studyday;
run;
I want to flag records based on following conditions
1. if studyday is +30 or -30 days of trt_changeday then flag the record closest to trt_changeday else ;
2. if studyday is out of range of +/ -30 days of trt_changeday then flag the record of the visit erlier to trt_changeday (Subject 4)
I need final output as below.
subject
studyday
visit
trt changeday
gap
flag
1
23
1
30
7
1
36
2
30
-6
1
1
40
3
30
-10
1
55
4
30
-25
1
78
5
30
-48
2
23
1
35
12
2
25
2
35
10
2
44
3
35
-9
1
3
12
1
24
12
3
18
2
24
6
3
30
3
24
-6
1
3
45
4
24
-21
3
66
5
24
-42
4
2
1
47
45
1
4
56
2
47
-9
4
89
3
47
-42
Thanks for the help.
... View more