Skip to contents

This function takes the an input data frame and a reference data frame (which is DM domain in most cases), and calculate the study day from reference date and target date. In case of unexpected conditions like reference date is not unique for each patient, or reference and input dates are not actual dates, NA will be returned for those records.

Usage

derive_study_day(
  sdtm_in,
  dm_domain,
  tgdt,
  refdt,
  study_day_var,
  merge_key = "USUBJID"
)

Arguments

sdtm_in

Input data frame that contains the target date.

dm_domain

Reference date frame that contains the reference date.

tgdt

Target date from sdtm_in that will be used to calculate the study day.

refdt

Reference date from dm_domain that will be used as reference to calculate the study day.

study_day_var

New study day variable name in the output. For example, AESTDY for AE domain and CMSTDY for CM domain.

merge_key

Character to represent the merging key between sdtm_in and dm_domain.

Value

Data frame that takes all columns from sdtm_in and a new variable to represent the calculated study day.

Examples

ae <- data.frame(
  USUBJID = c("study123-123", "study123-124", "study123-125"),
  AESTDTC = c("2012-01-01", "2012-04-14", "2012-04-14")
)
dm <- data.frame(
  USUBJID = c("study123-123", "study123-124", "study123-125"),
  RFSTDTC = c("2012-02-01", "2012-04-14", NA)
)
ae$AESTDTC <- as.Date(ae$AESTDTC)
dm$RFSTDTC <- as.Date(dm$RFSTDTC)
derive_study_day(ae, dm, "AESTDTC", "RFSTDTC", "AESTDY")
#>        USUBJID    AESTDTC AESTDY
#> 1 study123-123 2012-01-01    -31
#> 2 study123-124 2012-04-14      1
#> 3 study123-125 2012-04-14     NA