This article describes creating anADSL ADaM. Examplesare currently presented and tested usingDM,EX ,AE,LB andDSSDTM domains. However, other domains could be used.
Note:All examples assume CDISC SDTM and/or ADaMformat as input unless otherwise specified.
APxxSDT,APxxEDT, …)TRT0xP,TRT0xA)TRTSDT,TRTEDT,TRTDURD)LSTALVDT)To start, all data frames needed for the creation ofADSL should be read into the environment. This will be acompany specific process. Some of the data frames needed may beDM,EX,DS,AE, andLB.
For example purpose, the CDISC Pilot SDTM datasets—which are includedin{pharmaversesdtm}—are used.
library(admiral)library(dplyr,warn.conflicts =FALSE)library(pharmaversesdtm)library(lubridate)library(stringr)dm<- pharmaversesdtm::dmds<- pharmaversesdtm::dsex<- pharmaversesdtm::exae<- pharmaversesdtm::aelb<- pharmaversesdtm::lbdm<-convert_blanks_to_na(dm)ds<-convert_blanks_to_na(ds)ex<-convert_blanks_to_na(ex)ae<-convert_blanks_to_na(ae)lb<-convert_blanks_to_na(lb)TheDM domain is used as the basis forADSL:
| USUBJID | RFSTDTC | COUNTRY | AGE | SEX | RACE | ETHNIC | ARM | ACTARM |
|---|---|---|---|---|---|---|---|---|
| 01-701-1015 | 2014-01-02 | USA | 63 | F | WHITE | HISPANIC OR LATINO | Placebo | Placebo |
| 01-701-1023 | 2012-08-05 | USA | 64 | M | WHITE | HISPANIC OR LATINO | Placebo | Placebo |
| 01-701-1028 | 2013-07-19 | USA | 71 | M | WHITE | NOT HISPANIC OR LATINO | Xanomeline High Dose | Xanomeline High Dose |
| 01-701-1033 | 2014-03-18 | USA | 74 | M | WHITE | NOT HISPANIC OR LATINO | Xanomeline Low Dose | Xanomeline Low Dose |
| 01-701-1034 | 2014-07-01 | USA | 77 | F | WHITE | NOT HISPANIC OR LATINO | Xanomeline High Dose | Xanomeline High Dose |
| 01-701-1047 | 2013-02-12 | USA | 85 | F | WHITE | NOT HISPANIC OR LATINO | Placebo | Placebo |
| 01-701-1057 | NA | USA | 59 | F | WHITE | HISPANIC OR LATINO | Screen Failure | Screen Failure |
| 01-701-1097 | 2014-01-01 | USA | 68 | M | WHITE | NOT HISPANIC OR LATINO | Xanomeline Low Dose | Xanomeline Low Dose |
| 01-701-1111 | 2012-09-07 | USA | 81 | F | WHITE | NOT HISPANIC OR LATINO | Xanomeline Low Dose | Xanomeline Low Dose |
| 01-701-1115 | 2012-11-30 | USA | 84 | M | WHITE | NOT HISPANIC OR LATINO | Xanomeline Low Dose | Xanomeline Low Dose |
APxxSDT,APxxEDT, …)See the“Visit and PeriodVariables” vignette for more information.
If the variables are not derived based on a period reference dataset,they may be derived at a later point of the flow. For example, phaseslike “Treatment Phase” and “Follow up” could be derived based ontreatment start and end date.
TRT0xP,TRT0xA)The mapping of the treatment variables is left to the ADaMprogrammer. An example mapping for a study without periods may be:
For studies with periods see the“Visit and Period Variables”vignette.
TRTSDTM,TRTEDTM,TRTDURD)The functionderive_vars_merged() can be used to derivethe treatment start and end date/times using theex domain.A pre-processing step forex is required to convert thevariableEXSTDTC andEXSTDTC to datetimevariables and impute missing date or time components. Conversion andimputation is done byderive_vars_dtm().
Example calls:
# impute start and end time of exposure to first and last respectively,# do not impute dateex_ext<- ex%>%derive_vars_dtm(dtc = EXSTDTC,new_vars_prefix ="EXST" )%>%derive_vars_dtm(dtc = EXENDTC,new_vars_prefix ="EXEN",time_imputation ="last" )#> The default value of `ignore_seconds_flag` will change to "TRUE" in admiral#> 1.4.0.adsl<- adsl%>%derive_vars_merged(dataset_add = ex_ext,filter_add = (EXDOSE>0| (EXDOSE==0&str_detect(EXTRT,"PLACEBO")))&!is.na(EXSTDTM),new_vars =exprs(TRTSDTM = EXSTDTM,TRTSTMF = EXSTTMF),order =exprs(EXSTDTM, EXSEQ),mode ="first",by_vars =exprs(STUDYID, USUBJID) )%>%derive_vars_merged(dataset_add = ex_ext,filter_add = (EXDOSE>0| (EXDOSE==0&str_detect(EXTRT,"PLACEBO")))&!is.na(EXENDTM),new_vars =exprs(TRTEDTM = EXENDTM,TRTETMF = EXENTMF),order =exprs(EXENDTM, EXSEQ),mode ="last",by_vars =exprs(STUDYID, USUBJID) )This call returns the original data frame with the columnTRTSDTM,TRTSTMF,TRTEDTM, andTRTETMF added. Exposure observations with incomplete dateand zero doses of non placebo treatments are ignored. Missing time partsare imputed as first or last for start and end date respectively.
The datetime variables returned can be converted to dates using thederive_vars_dtm_to_dt() function.
Now, thatTRTSDT andTRTEDT are derived,the functionderive_var_trtdurd() can be used to calculatethe Treatment duration (TRTDURD).
| USUBJID | RFSTDTC | TRTSDTM | TRTSDT | TRTEDTM | TRTEDT | TRTDURD |
|---|---|---|---|---|---|---|
| 01-701-1015 | 2014-01-02 | 2014-01-02 | 2014-01-02 | 2014-07-02 23:59:59 | 2014-07-02 | 182 |
| 01-701-1023 | 2012-08-05 | 2012-08-05 | 2012-08-05 | 2012-09-01 23:59:59 | 2012-09-01 | 28 |
| 01-701-1028 | 2013-07-19 | 2013-07-19 | 2013-07-19 | 2014-01-14 23:59:59 | 2014-01-14 | 180 |
| 01-701-1033 | 2014-03-18 | 2014-03-18 | 2014-03-18 | 2014-03-31 23:59:59 | 2014-03-31 | 14 |
| 01-701-1034 | 2014-07-01 | 2014-07-01 | 2014-07-01 | 2014-12-30 23:59:59 | 2014-12-30 | 183 |
| 01-701-1047 | 2013-02-12 | 2013-02-12 | 2013-02-12 | 2013-03-09 23:59:59 | 2013-03-09 | 26 |
| 01-701-1057 | NA | NA | NA | NA | NA | NA |
| 01-701-1097 | 2014-01-01 | 2014-01-01 | 2014-01-01 | 2014-07-09 23:59:59 | 2014-07-09 | 190 |
| 01-701-1111 | 2012-09-07 | 2012-09-07 | 2012-09-07 | 2012-09-16 23:59:59 | 2012-09-16 | 10 |
| 01-701-1115 | 2012-11-30 | 2012-11-30 | 2012-11-30 | 2013-01-23 23:59:59 | 2013-01-23 | 55 |
EOSDT)The functionsderive_vars_dt() andderive_vars_merged() can be used to derive a dispositiondate. First the character disposition date (DS.DSSTDTC) isconverted to a numeric date (DSSTDT) callingderive_vars_dt(). TheDS dataset is extendedby theDSSTDT variable because the date is required byother derivations, e.g.,RANDDT as well. Then the relevantdisposition date is selected by adjusting thefilter_addargument.
To add the End of Study date (EOSDT) to the inputdataset, a call could be:
# convert character date to numeric date without imputationds_ext<-derive_vars_dt( ds,dtc = DSSTDTC,new_vars_prefix ="DSST")adsl<- adsl%>%derive_vars_merged(dataset_add = ds_ext,by_vars =exprs(STUDYID, USUBJID),new_vars =exprs(EOSDT = DSSTDT),filter_add = DSCAT=="DISPOSITION EVENT"& DSDECOD!="SCREEN FAILURE" )Theds_ext dataset:
| USUBJID | DSCAT | DSDECOD | DSTERM | DSSTDT | DSSTDTC |
|---|---|---|---|---|---|
| 01-701-1015 | PROTOCOL MILESTONE | RANDOMIZED | RANDOMIZED | 2014-01-02 | 2014-01-02 |
| 01-701-1015 | DISPOSITION EVENT | COMPLETED | PROTOCOL COMPLETED | 2014-07-02 | 2014-07-02 |
| 01-701-1015 | OTHER EVENT | FINAL LAB VISIT | FINAL LAB VISIT | 2014-07-02 | 2014-07-02 |
| 01-701-1023 | PROTOCOL MILESTONE | RANDOMIZED | RANDOMIZED | 2012-08-05 | 2012-08-05 |
| 01-701-1023 | DISPOSITION EVENT | ADVERSE EVENT | ADVERSE EVENT | 2012-09-02 | 2012-09-02 |
| 01-701-1023 | OTHER EVENT | FINAL LAB VISIT | FINAL LAB VISIT | 2012-09-02 | 2012-09-02 |
| 01-701-1023 | OTHER EVENT | FINAL RETRIEVAL VISIT | FINAL RETRIEVAL VISIT | 2013-02-18 | 2013-02-18 |
| 01-701-1028 | PROTOCOL MILESTONE | RANDOMIZED | RANDOMIZED | 2013-07-19 | 2013-07-19 |
| 01-701-1028 | DISPOSITION EVENT | COMPLETED | PROTOCOL COMPLETED | 2014-01-14 | 2014-01-14 |
| 01-701-1028 | OTHER EVENT | FINAL LAB VISIT | FINAL LAB VISIT | 2014-01-14 | 2014-01-14 |
Theadsl dataset:
| USUBJID | EOSDT |
|---|---|
| 01-701-1015 | 2014-07-02 |
| 01-701-1023 | 2012-09-02 |
| 01-701-1028 | 2014-01-14 |
| 01-701-1033 | 2014-04-14 |
| 01-701-1034 | 2014-12-30 |
| 01-701-1047 | 2013-03-29 |
| 01-701-1057 | NA |
| 01-701-1097 | 2014-07-09 |
| 01-701-1111 | 2012-09-17 |
| 01-701-1115 | 2013-01-23 |
Thederive_vars_dt() function allows to impute partialdates as well. If imputation is needed and missing days are to beimputed to the first of the month and missing months to the first monthof the year, sethighest_imputation = "M".
EOSSTT)The functionderive_vars_merged() can be used to derivethe End of Study status (EOSSTT) based onDSCAT andDSDECOD fromDS. Therelevant observations are selected by adjusting thefilter_add argument. A function mappingDSDECOD values toEOSSTT values can be definedand used in thenew_vars argument. The mapping for the callbelow is
"COMPLETED" ifDSDECOD == "COMPLETED"NA_character_ ifDSDECOD is"SCREEN FAILURE""DISCONTINUED" otherwiseExample functionformat_eosstt():
format_eosstt<-function(x) {case_when( x%in%c("COMPLETED")~"COMPLETED", x%in%c("SCREEN FAILURE")~NA_character_,TRUE~"DISCONTINUED" )}The customized mapping functionformat_eosstt() can nowbe passed to the main function. For subjects without a disposition eventthe end of study status is set to"ONGOING" by specifyingthemissing_values argument.
adsl<- adsl%>%derive_vars_merged(dataset_add = ds,by_vars =exprs(STUDYID, USUBJID),filter_add = DSCAT=="DISPOSITION EVENT",new_vars =exprs(EOSSTT =format_eosstt(DSDECOD)),missing_values =exprs(EOSSTT ="ONGOING") )| USUBJID | EOSDT | EOSSTT |
|---|---|---|
| 01-701-1015 | 2014-07-02 | COMPLETED |
| 01-701-1023 | 2012-09-02 | DISCONTINUED |
| 01-701-1028 | 2014-01-14 | COMPLETED |
| 01-701-1033 | 2014-04-14 | DISCONTINUED |
| 01-701-1034 | 2014-12-30 | COMPLETED |
| 01-701-1047 | 2013-03-29 | DISCONTINUED |
| 01-701-1057 | NA | NA |
| 01-701-1097 | 2014-07-09 | COMPLETED |
| 01-701-1111 | 2012-09-17 | DISCONTINUED |
| 01-701-1115 | 2013-01-23 | DISCONTINUED |
This call would return the input dataset with the columnEOSSTT added.
If the derivation must be changed, the user can create his/her ownfunction to mapDSDECOD to a suitableEOSSTTvalue.
DCSREAS,DCSREASP)The main reason for discontinuation is usually stored inDSDECOD whileDSTERM provides additionaldetails regarding subject’s discontinuation (e.g., description of"OTHER").
The functionderive_vars_merged() can be used to derivea disposition reason (along with the details, if required) at a specifictimepoint. The relevant observations are selected by adjusting thefilter_add argument.
To derive the End of Study reason(s) (DCSREAS andDCSREASP), the function will mapDCSREAS asDSDECOD, andDCSREASP asDSTERMifDSDECOD is not"COMPLETED","SCREEN FAILURE", orNA,NAotherwise.
adsl<- adsl%>%derive_vars_merged(dataset_add = ds,by_vars =exprs(USUBJID),new_vars =exprs(DCSREAS = DSDECOD,DCSREASP = DSTERM),filter_add = DSCAT=="DISPOSITION EVENT"&!(DSDECOD%in%c("SCREEN FAILURE","COMPLETED",NA)) )| USUBJID | EOSDT | EOSSTT | DCSREAS | DCSREASP |
|---|---|---|---|---|
| 01-701-1015 | 2014-07-02 | COMPLETED | NA | NA |
| 01-701-1023 | 2012-09-02 | DISCONTINUED | ADVERSE EVENT | ADVERSE EVENT |
| 01-701-1028 | 2014-01-14 | COMPLETED | NA | NA |
| 01-701-1033 | 2014-04-14 | DISCONTINUED | STUDY TERMINATED BY SPONSOR | SPONSOR DECISION (STUDY OR PATIENT DISCONTINUED BY THESPONSOR) |
| 01-701-1034 | 2014-12-30 | COMPLETED | NA | NA |
| 01-701-1047 | 2013-03-29 | DISCONTINUED | ADVERSE EVENT | ADVERSE EVENT |
| 01-701-1057 | NA | NA | NA | NA |
| 01-701-1097 | 2014-07-09 | COMPLETED | NA | NA |
| 01-701-1111 | 2012-09-17 | DISCONTINUED | ADVERSE EVENT | ADVERSE EVENT |
| 01-701-1115 | 2013-01-23 | DISCONTINUED | ADVERSE EVENT | ADVERSE EVENT |
This call would return the input dataset with the columnDCSREAS andDCSREASP added.
If the derivation must be changed, the user can define thatderivation in thefilter_add argument of the function tomapDSDECOD andDSTERM to a suitableDCSREAS/DCSREASP value.
The call below mapsDCSREAS andDCREASP asfollows:
DCSREAS asDSDECOD ifDSDECODis not"COMPLETED" orNA,NAotherwiseDCSREASP asDSTERM ifDSDECODis equal toOTHER,NA otherwiseadsl<- adsl%>%derive_vars_merged(dataset_add = ds,by_vars =exprs(USUBJID),new_vars =exprs(DCSREAS = DSDECOD),filter_add = DSCAT=="DISPOSITION EVENT"& DSDECOD%notin%c("SCREEN FAILURE","COMPLETED",NA) )%>%derive_vars_merged(dataset_add = ds,by_vars =exprs(USUBJID),new_vars =exprs(DCSREASP = DSTERM),filter_add = DSCAT=="DISPOSITION EVENT"& DSDECOD%in%"OTHER" )| USUBJID | EOSDT | EOSSTT | DCSREAS | DCSREASP |
|---|---|---|---|---|
| 01-701-1015 | 2014-07-02 | COMPLETED | NA | NA |
| 01-701-1023 | 2012-09-02 | DISCONTINUED | ADVERSE EVENT | NA |
| 01-701-1028 | 2014-01-14 | COMPLETED | NA | NA |
| 01-701-1033 | 2014-04-14 | DISCONTINUED | STUDY TERMINATED BY SPONSOR | NA |
| 01-701-1034 | 2014-12-30 | COMPLETED | NA | NA |
| 01-701-1047 | 2013-03-29 | DISCONTINUED | ADVERSE EVENT | NA |
| 01-701-1057 | NA | NA | NA | NA |
| 01-701-1097 | 2014-07-09 | COMPLETED | NA | NA |
| 01-701-1111 | 2012-09-17 | DISCONTINUED | ADVERSE EVENT | NA |
| 01-701-1115 | 2013-01-23 | DISCONTINUED | ADVERSE EVENT | NA |
RANDDT)The functionderive_vars_merged() can be used to deriverandomization date variable. To map Randomization Date(RANDDT), the call would be:
adsl<- adsl%>%derive_vars_merged(dataset_add = ds_ext,filter_add = DSDECOD=="RANDOMIZED",by_vars =exprs(STUDYID, USUBJID),new_vars =exprs(RANDDT = DSSTDT) )This call would return the input dataset with the columnRANDDT is added.
| USUBJID | RANDDT |
|---|---|
| 01-701-1015 | 2014-01-02 |
| 01-701-1023 | 2012-08-05 |
| 01-701-1028 | 2013-07-19 |
| 01-701-1033 | 2014-03-18 |
| 01-701-1034 | 2014-07-01 |
| 01-701-1047 | 2013-02-12 |
| 01-701-1057 | NA |
| 01-701-1097 | 2014-01-01 |
| 01-701-1111 | 2012-09-07 |
| 01-701-1115 | 2012-11-30 |
DTHDT)The functionderive_vars_dt() can be used to deriveDTHDT. This function allows the user to impute the date aswell.
Example calls:
| USUBJID | TRTEDT | DTHDTC | DTHDT | DTHFL |
|---|---|---|---|---|
| 01-701-1211 | 2013-01-12 | 2013-01-14 | 2013-01-14 | Y |
| 01-701-1442 | 2014-04-26 | NA | NA | NA |
| 01-704-1445 | 2014-11-01 | 2014-11-01 | 2014-11-01 | Y |
| 01-705-1058 | NA | NA | NA | NA |
| 01-708-1347 | 2013-06-18 | NA | NA | NA |
| 01-710-1083 | 2013-08-01 | 2013-08-02 | 2013-08-02 | Y |
| 01-710-1235 | 2013-03-27 | NA | NA | NA |
| 01-715-1207 | 2013-05-27 | NA | NA | NA |
| 01-718-1172 | 2013-11-29 | NA | NA | NA |
This call would return the input dataset with the columnsDTHDT added and, by default, the associated date imputationflag (DTHDTF) populated with the controlled terminologyoutlined in the ADaM IG for date imputations. If the imputation flag isnot required, the user must set the argumentflag_imputation to"none".
If imputation is needed and the date is to be imputed to the firstday of the month/year the call would be:
See alsoDate and Time Imputation.
DTHCAUS)The cause of deathDTHCAUS can be derived using thefunctionderive_vars_extreme_event().
Since the cause of death could be collected/mapped in differentdomains (e.g. DS,AE,DD), it isimportant the user specifies the right source(s) to derive the cause ofdeath from.
For example, if the date of death is collected in the AE form whenthe AE is Fatal, the cause of death would be set to the preferred term(AEDECOD) of that Fatal AE, while if the date of death iscollected in theDS form, the cause of death would be setto the disposition term (DSTERM). To achieve this, theevent() objects withinderive_vars_extreme_event() must be specified and definedsuch that they fit the study requirement.
An example call toderive_vars_extreme_event() wouldbe:
adsl<- adsl%>%derive_vars_extreme_event(by_vars =exprs(STUDYID, USUBJID),events =list(event(dataset_name ="ae",condition = AEOUT=="FATAL",set_values_to =exprs(DTHCAUS = AEDECOD), ),event(dataset_name ="ds",condition = DSDECOD=="DEATH"&grepl("DEATH DUE TO", DSTERM),set_values_to =exprs(DTHCAUS = DSTERM), ) ),source_datasets =list(ae = ae,ds = ds),tmp_event_nr_var = event_nr,order =exprs(event_nr),mode ="first",new_vars =exprs(DTHCAUS) )| USUBJID | EOSDT | DTHDTC | DTHDT | DTHCAUS |
|---|---|---|---|---|
| 01-701-1211 | 2013-01-14 | 2013-01-14 | 2013-01-14 | SUDDEN DEATH |
| 01-704-1445 | 2014-11-01 | 2014-11-01 | 2014-11-01 | COMPLETED SUICIDE |
| 01-710-1083 | 2013-08-02 | 2013-08-02 | 2013-08-02 | MYOCARDIAL INFARCTION |
The function also offers the option to add some traceabilityvariables (e.g. DTHDOM would store the domain where thedate of death is collected, andDTHSEQ would store thexxSEQ value of that domain). The traceability variablesshould be added to theevent() calls and included in thenew_vars parameter ofderive_vars_extreme_event().
adsl<- adsl%>%select(-DTHCAUS)%>%# remove it before deriving it againderive_vars_extreme_event(by_vars =exprs(STUDYID, USUBJID),events =list(event(dataset_name ="ae",condition = AEOUT=="FATAL",set_values_to =exprs(DTHCAUS = AEDECOD,DTHDOM ="AE",DTHSEQ = AESEQ), ),event(dataset_name ="ds",condition = DSDECOD=="DEATH"&grepl("DEATH DUE TO", DSTERM),set_values_to =exprs(DTHCAUS = DSTERM,DTHDOM ="DS",DTHSEQ = DSSEQ), ) ),source_datasets =list(ae = ae,ds = ds),tmp_event_nr_var = event_nr,order =exprs(event_nr),mode ="first",new_vars =exprs(DTHCAUS, DTHDOM, DTHSEQ) )| USUBJID | TRTEDT | DTHDTC | DTHDT | DTHCAUS | DTHDOM | DTHSEQ |
|---|---|---|---|---|---|---|
| 01-701-1211 | 2013-01-12 | 2013-01-14 | 2013-01-14 | SUDDEN DEATH | AE | 9 |
| 01-704-1445 | 2014-11-01 | 2014-11-01 | 2014-11-01 | COMPLETED SUICIDE | AE | 1 |
| 01-710-1083 | 2013-08-01 | 2013-08-02 | 2013-08-02 | MYOCARDIAL INFARCTION | AE | 1 |
Following the derivation ofDTHCAUS and relatedtraceability variables, it is then possible to derive grouping variablessuch as death categories (DTHCGRx) using standard tidyversecode.
The functionderive_vars_duration() can be used toderive duration relative to death like the Relative Day of Death(DTHADY) or the numbers of days from last dose to death(LDDTHELD).
Example calls:
adsl<- adsl%>%derive_vars_duration(new_var = LDDTHELD,start_date = TRTEDT,end_date = DTHDT,add_one =FALSE )| USUBJID | TRTEDT | DTHDTC | DTHDT | DTHCAUS | DTHADY | LDDTHELD |
|---|---|---|---|---|---|---|
| 01-701-1211 | 2013-01-12 | 2013-01-14 | 2013-01-14 | SUDDEN DEATH | 61 | 2 |
| 01-704-1445 | 2014-11-01 | 2014-11-01 | 2014-11-01 | COMPLETED SUICIDE | 175 | 0 |
| 01-710-1083 | 2013-08-01 | 2013-08-02 | 2013-08-02 | MYOCARDIAL INFARCTION | 12 | 1 |
LSTALVDT)Similarly as for the cause of death (DTHCAUS), the lastknown alive date (LSTALVDT) can be derived from multiplessources usingderive_vars_extreme_event().
An example could be (DTC dates are converted to numeric datesimputing missing day and month to the first):
adsl<- adsl%>%derive_vars_extreme_event(by_vars =exprs(STUDYID, USUBJID),events =list(event(dataset_name ="ae",order =exprs(AESTDTC, AESEQ),condition =!is.na(AESTDTC),set_values_to =exprs(LSTALVDT =convert_dtc_to_dt(AESTDTC,highest_imputation ="M"),seq = AESEQ ), ),event(dataset_name ="ae",order =exprs(AEENDTC, AESEQ),condition =!is.na(AEENDTC),set_values_to =exprs(LSTALVDT =convert_dtc_to_dt(AEENDTC,highest_imputation ="M"),seq = AESEQ ), ),event(dataset_name ="lb",order =exprs(LBDTC, LBSEQ),condition =!is.na(LBDTC),set_values_to =exprs(LSTALVDT =convert_dtc_to_dt(LBDTC,highest_imputation ="M"),seq = LBSEQ ), ),event(dataset_name ="adsl",condition =!is.na(TRTEDT),set_values_to =exprs(LSTALVDT = TRTEDT,seq =0), ) ),source_datasets =list(ae = ae,lb = lb,adsl = adsl),tmp_event_nr_var = event_nr,order =exprs(LSTALVDT, seq, event_nr),mode ="last",new_vars =exprs(LSTALVDT) )| USUBJID | TRTEDT | DTHDTC | LSTALVDT |
|---|---|---|---|
| 01-701-1015 | 2014-07-02 | NA | 2014-07-02 |
| 01-701-1023 | 2012-09-01 | NA | 2012-09-02 |
| 01-701-1028 | 2014-01-14 | NA | 2014-01-14 |
| 01-701-1033 | 2014-03-31 | NA | 2014-04-14 |
| 01-701-1034 | 2014-12-30 | NA | 2014-12-30 |
| 01-701-1047 | 2013-03-09 | NA | 2013-04-07 |
| 01-701-1097 | 2014-07-09 | NA | 2014-07-09 |
| 01-701-1111 | 2012-09-16 | NA | 2012-09-17 |
| 01-701-1115 | 2013-01-23 | NA | 2013-01-23 |
| 01-701-1118 | 2014-09-09 | NA | 2014-09-09 |
Traceability variables can be added by specifying the variables intheset_values_to parameter of theevent()function.
adsl<- adsl%>%select(-LSTALVDT)%>%# created in the previous callderive_vars_extreme_event(by_vars =exprs(STUDYID, USUBJID),events =list(event(dataset_name ="ae",order =exprs(AESTDTC, AESEQ),condition =!is.na(AESTDTC),set_values_to =exprs(LSTALVDT =convert_dtc_to_dt(AESTDTC,highest_imputation ="M"),LALVSEQ = AESEQ,LALVDOM ="AE",LALVVAR ="AESTDTC" ), ),event(dataset_name ="ae",order =exprs(AEENDTC, AESEQ),condition =!is.na(AEENDTC),set_values_to =exprs(LSTALVDT =convert_dtc_to_dt(AEENDTC,highest_imputation ="M"),LALVSEQ = AESEQ,LALVDOM ="AE",LALVVAR ="AEENDTC" ), ),event(dataset_name ="lb",order =exprs(LBDTC, LBSEQ),condition =!is.na(LBDTC),set_values_to =exprs(LSTALVDT =convert_dtc_to_dt(LBDTC,highest_imputation ="M"),LALVSEQ = LBSEQ,LALVDOM ="LB",LALVVAR ="LBDTC" ), ),event(dataset_name ="adsl",condition =!is.na(TRTEDT),set_values_to =exprs(LSTALVDT = TRTEDT,LALVSEQ =NA_integer_,LALVDOM ="ADSL",LALVVAR ="TRTEDTM"), ) ),source_datasets =list(ae = ae,lb = lb,adsl = adsl),tmp_event_nr_var = event_nr,order =exprs(LSTALVDT, LALVSEQ, event_nr),mode ="last",new_vars =exprs(LSTALVDT, LALVSEQ, LALVDOM, LALVVAR) )| USUBJID | TRTEDT | DTHDTC | LSTALVDT | LALVDOM | LALVSEQ | LALVVAR |
|---|---|---|---|---|---|---|
| 01-701-1015 | 2014-07-02 | NA | 2014-07-02 | ADSL | NA | TRTEDTM |
| 01-701-1023 | 2012-09-01 | NA | 2012-09-02 | LB | 107 | LBDTC |
| 01-701-1028 | 2014-01-14 | NA | 2014-01-14 | ADSL | NA | TRTEDTM |
| 01-701-1033 | 2014-03-31 | NA | 2014-04-14 | LB | 107 | LBDTC |
| 01-701-1034 | 2014-12-30 | NA | 2014-12-30 | ADSL | NA | TRTEDTM |
| 01-701-1047 | 2013-03-09 | NA | 2013-04-07 | LB | 134 | LBDTC |
| 01-701-1097 | 2014-07-09 | NA | 2014-07-09 | ADSL | NA | TRTEDTM |
| 01-701-1111 | 2012-09-16 | NA | 2012-09-17 | LB | 73 | LBDTC |
| 01-701-1115 | 2013-01-23 | NA | 2013-01-23 | ADSL | NA | TRTEDTM |
| 01-701-1118 | 2014-09-09 | NA | 2014-09-09 | ADSL | NA | TRTEDTM |
AGEGR1 orREGION1)Numeric and categorical variables (AGE,RACE,COUNTRY, etc.) may need to be grouped toperform the required analysis.{admiral} provides thederive_vars_cat() function to create such groups. Thisfunction is especially useful if more than one variable needs to becreated for each condition, e.g.,AGEGR1 andAGEGR1N.
Additionally, one needs to be careful when considering the order ofthe conditions in the lookup table. The category is assigned based onthe first match. That meanscatch-all conditions must comeafter specific conditions, e.g. !is.na(COUNTRY) must comeafterCOUNTRY %in% c("CAN", "USA").
# create lookup tablesagegr1_lookup<-exprs(~condition,~AGEGR1, AGE<18,"<18",between(AGE,18,64),"18-64", AGE>64,">64",is.na(AGE),"Missing")region1_lookup<-exprs(~condition,~REGION1, COUNTRY%in%c("CAN","USA"),"North America",!is.na(COUNTRY),"Rest of the World",is.na(COUNTRY),"Missing")adsl<- adsl%>%derive_vars_cat(definition = agegr1_lookup )%>%derive_vars_cat(definition = region1_lookup )Alternatively, you can also solve this task with customfunctions:
format_agegr1<-function(var_input) {case_when( var_input<18~"<18",between(var_input,18,64)~"18-64", var_input>64~">64",TRUE~"Missing" )}format_region1<-function(var_input) {case_when( var_input%in%c("CAN","USA")~"North America",!is.na(var_input)~"Rest of the World",TRUE~"Missing" )}adsl%>%mutate(AGEGR1 =format_agegr1(AGE),REGION1 =format_region1(COUNTRY) )| USUBJID | AGE | SEX | COUNTRY | AGEGR1 | REGION1 |
|---|---|---|---|---|---|
| 01-701-1015 | 63 | F | USA | 18-64 | North America |
| 01-701-1023 | 64 | M | USA | 18-64 | North America |
| 01-701-1028 | 71 | M | USA | >64 | North America |
| 01-701-1033 | 74 | M | USA | >64 | North America |
| 01-701-1034 | 77 | F | USA | >64 | North America |
| 01-701-1047 | 85 | F | USA | >64 | North America |
| 01-701-1057 | 59 | F | USA | 18-64 | North America |
| 01-701-1097 | 68 | M | USA | >64 | North America |
| 01-701-1111 | 81 | F | USA | >64 | North America |
| 01-701-1115 | 84 | M | USA | >64 | North America |
SAFFL)Since the populations flags are mainly company/study specific nodedicated functions are provided, but in most cases they can easily bederived usingderive_var_merged_exist_flag.
An example of an implementation could be:
adsl<- adsl%>%derive_var_merged_exist_flag(dataset_add = ex,by_vars =exprs(STUDYID, USUBJID),new_var = SAFFL,false_value ="N",missing_value ="N",condition = (EXDOSE>0| (EXDOSE==0&str_detect(EXTRT,"PLACEBO"))) )| USUBJID | TRTSDT | ARM | ACTARM | SAFFL |
|---|---|---|---|---|
| 01-701-1015 | 2014-01-02 | Placebo | Placebo | Y |
| 01-701-1023 | 2012-08-05 | Placebo | Placebo | Y |
| 01-701-1028 | 2013-07-19 | Xanomeline High Dose | Xanomeline High Dose | Y |
| 01-701-1033 | 2014-03-18 | Xanomeline Low Dose | Xanomeline Low Dose | Y |
| 01-701-1034 | 2014-07-01 | Xanomeline High Dose | Xanomeline High Dose | Y |
| 01-701-1047 | 2013-02-12 | Placebo | Placebo | Y |
| 01-701-1057 | NA | Screen Failure | Screen Failure | N |
| 01-701-1097 | 2014-01-01 | Xanomeline Low Dose | Xanomeline Low Dose | Y |
| 01-701-1111 | 2012-09-07 | Xanomeline Low Dose | Xanomeline Low Dose | Y |
| 01-701-1115 | 2012-11-30 | Xanomeline Low Dose | Xanomeline Low Dose | Y |
The users can add specific code to cover their need for theanalysis.
The following functions are helpful for many ADSL derivations:
derive_vars_merged() - Merge Variables from a Datasetto the Input Datasetderive_var_merged_exist_flag() - Merge an ExistenceFlagderive_var_merged_summary() - Merge SummaryVariablesSee alsoGeneric Functions.
Adding labels and attributes for SAS transport files is supported bythe following packages:
metacore:establish a common foundation for the use of metadata within an Rsession.
metatools:enable the use of metacore objects. Metatools can be used to builddatasets or enhance columns in existing datasets as well as checkingdatasets against the metadata.
xportr:functionality to associate all metadata information to a local R dataframe, perform data set level validation checks and convert into atransportv5 file(xpt).
NOTE: All these packages are in the experimental phase, but thevision is to have them associated with an End to End pipeline under theumbrella of thepharmaverse. An example ofapplying metadata and perform associated checks can be found at thepharmaverse E2Eexample.
| ADaM | Sourcing Command |
|---|---|
| ADSL | use_ad_template("ADSL") |