I am trying to create a new integer variable AE (1 or 0).
I have three flags (AEACN12, AEACN13, AEACN) per patient. The dataset has multiple records per patient. If at least one of the three flags is equal to "DRUG WITHDRAWN", I would like the flag only that record with AE=1. The flags can have other values or missing. If none of the three flags equals "DRUG WITHDRAWN", then AE=0.
I am using data.table approach but the code below is not producing what I need. Can you help?
AE <- adae[SAFFL=="Y"][AEREL=="Y" & AETRTFL=="Y", `:=`(AE=fifelse(any(AEACN12=="DRUG WITHDRAWN", AEACN13=="DRUG WITHDRAWN", AEACN=="DRUG WITHDRAWN"), 1, 0))][order(USUBJID)][,.(USUBJID,AEACN12,AEACN13,AEACN, AE, SAFFL, AEREL, AETRTFL)]