library(tibble)
library(dplyr, warn.conflicts = FALSE)
library(lubridate)
adsl <- tibble(STUDYID = "xyz", USUBJID = c("1", "2"))
# Add period variables to ADSL
period_ref <- tribble(
~USUBJID, ~APERIOD, ~APERSDT, ~APEREDT,
"1", 1, "2021-01-04", "2021-02-06",
"1", 2, "2021-02-07", "2021-03-07",
"2", 1, "2021-02-02", "2021-03-02",
"2", 2, "2021-03-03", "2021-04-01"
) %>%
mutate(
STUDYID = "xyz",
APERIOD = as.integer(APERIOD),
across(matches("APER[ES]DT"), ymd)
)
derive_vars_period(
adsl,
dataset_ref = period_ref,
new_vars = exprs(APxxSDT = APERSDT, APxxEDT = APEREDT)
) %>%
select(STUDYID, USUBJID, AP01SDT, AP01EDT, AP02SDT, AP02EDT)
# Add phase variables to ADSL
phase_ref <- tribble(
~USUBJID, ~APHASEN, ~PHSDT, ~PHEDT, ~APHASE,
"1", 1, "2021-01-04", "2021-02-06", "TREATMENT",
"1", 2, "2021-02-07", "2021-03-07", "FUP",
"2", 1, "2021-02-02", "2021-03-02", "TREATMENT"
) %>%
mutate(
STUDYID = "xyz",
APHASEN = as.integer(APHASEN),
across(matches("PH[ES]DT"), ymd)
)
derive_vars_period(
adsl,
dataset_ref = phase_ref,
new_vars = exprs(PHwSDT = PHSDT, PHwEDT = PHEDT, APHASEw = APHASE)
) %>%
select(STUDYID, USUBJID, PH1SDT, PH1EDT, PH2SDT, PH2EDT, APHASE1, APHASE2)
# Add subperiod variables to ADSL
subperiod_ref <- tribble(
~USUBJID, ~APERIOD, ~ASPER, ~ASPRSDT, ~ASPREDT,
"1", 1, 1, "2021-01-04", "2021-01-19",
"1", 1, 2, "2021-01-20", "2021-02-06",
"1", 2, 1, "2021-02-07", "2021-03-07",
"2", 1, 1, "2021-02-02", "2021-03-02",
"2", 2, 1, "2021-03-03", "2021-04-01"
) %>%
mutate(
STUDYID = "xyz",
APERIOD = as.integer(APERIOD),
ASPER = as.integer(ASPER),
across(matches("ASPR[ES]DT"), ymd)
)
derive_vars_period(
adsl,
dataset_ref = subperiod_ref,
new_vars = exprs(PxxSwSDT = ASPRSDT, PxxSwEDT = ASPREDT)
) %>%
select(STUDYID, USUBJID, P01S1SDT, P01S1EDT, P01S2SDT, P01S2EDT, P02S1SDT, P02S1EDT)
Run the code above in your browser using DataLab