Dear,
I need to populate IMPDAY variable value for records having flag='Y'. The first record with flag='Y' after last record where flag='N' then set impday=lday. for all records until another record with flag='N'
data one;
input id flag $ lday;
datalines;
1 N 1
1 N 3
1 Y 4
1 Y 6
1 Y 10
1 N 12
1 Y 15
1 N 20 2 Y 10 2 Y 15 3 Y 20
;
OUTPUT NEEDED
ID FLAG LDAY IMPDAY
1 N 1
1 N 3
1 Y 4 4
1 Y 6 4
1 Y 10 4
1 N 12
1 Y 15 15
1 N 20 2 Y 10 10 2 Y 15 10 3 Y 20 20
For OBS 3,4,5, the impday=4 because obs=3 is first lday after flag=N. For obs=7, the impday=15, because it s first day after flag='N'.
For id in 2 and 3, if there are no obs with flag='N' then i need to populate first record value as IMPDAY. Please suggest. Thank you
... View more