This check identifies EXSTDTC values that are after EXENDTC values

check_ex_exstdtc_after_exendtc(EX)

Arguments

EX

Exposure SDTM dataset with variables USUBJID,EXTRT,EXSTDTC,EXENDTC

Value

boolean value if check failed or passed with 'msg' attribute if the test failed

Author

Sara Bodach

Examples


EX <- data.frame(
 STUDYID = 1,
 USUBJID = 1:12,
 EXTRT = "SOME DRUG",
 EXSTDTC = c("2017-01-01","2017-01-03","2017-01-01T14:26","2017","2017-02","2017"      ,""    ,
             "2017"   ,"2017-01-01T14:26","2017-01-01T14:26","2017-01-01T14","2017-01-01T14:26:02")
             ,
 EXENDTC = c("2017-01-01","2017-01-02","2017-01-01T14:25","2015","2017-01","2016-01-01","2000",
             "2017-02","2017-01-01"      ,"2017-01","2017-01-01T13","2017-01-01T14:26:01")
             ,
 EXOCCUR = "Y",
 VISIT = "CYCLE 1 DAY 1",
 stringsAsFactors=FALSE
)

check_ex_exstdtc_after_exendtc(EX)
#> [1] FALSE
#> attr(,"msg")
#> [1] "EX has 6 record(s) with EXSTDTC after EXENDTC. "
#> attr(,"data")
#>   USUBJID     EXTRT          EXSTDTC          EXENDTC         VISIT EXOCCUR
#> 1       2 SOME DRUG       2017-01-03       2017-01-02 CYCLE 1 DAY 1       Y
#> 2       3 SOME DRUG 2017-01-01T14:26 2017-01-01T14:25 CYCLE 1 DAY 1       Y
#> 3       4 SOME DRUG             2017             2015 CYCLE 1 DAY 1       Y
#> 4       5 SOME DRUG          2017-02          2017-01 CYCLE 1 DAY 1       Y
#> 5       6 SOME DRUG             2017       2016-01-01 CYCLE 1 DAY 1       Y
#> 6      11 SOME DRUG    2017-01-01T14    2017-01-01T13 CYCLE 1 DAY 1       Y

EX$EXOCCUR <- NULL
EX$VISIT <- NULL
check_ex_exstdtc_after_exendtc(EX)
#> [1] FALSE
#> attr(,"msg")
#> [1] "EX has 6 record(s) with EXSTDTC after EXENDTC. "
#> attr(,"data")
#>   USUBJID     EXTRT          EXSTDTC          EXENDTC
#> 1       2 SOME DRUG       2017-01-03       2017-01-02
#> 2       3 SOME DRUG 2017-01-01T14:26 2017-01-01T14:25
#> 3       4 SOME DRUG             2017             2015
#> 4       5 SOME DRUG          2017-02          2017-01
#> 5       6 SOME DRUG             2017       2016-01-01
#> 6      11 SOME DRUG    2017-01-01T14    2017-01-01T13

EX$EXTRT <- NULL
check_ex_exstdtc_after_exendtc(EX)
#> [1] FALSE
#> attr(,"msg")
#> [1] "EX is missing the variable: EXTRT"