Merge a (Imputed) Date VariableSource:
This function is deprecated, please use
Merge a imputed date variable and date imputation flag from a dataset to the input dataset. The observations to merge can be selected by a condition and/or selecting the first or last observation for each by group.
derive_vars_merged_dt( dataset, dataset_add, by_vars, order = NULL, new_vars_prefix, filter_add = NULL, mode = NULL, dtc, date_imputation = NULL, flag_imputation = "auto", min_dates = NULL, max_dates = NULL, preserve = FALSE, check_type = "warning", duplicate_msg = NULL )
The variables specified by the
by_varsargument are expected.
The variables specified by the
dtc, and the
orderargument are expected.
The input dataset and the selected observations from the additional dataset are merged by the specified by variables. The by variables must be a unique key of the selected observations.
Permitted Values: list of variables created by
If the argument is set to a non-null value, for each by group the first or last observation from the additional dataset is selected with respect to the specified order. The imputed date variable can be specified as well (see examples below).
Please note that
NAis considered as the last value. I.e., if a order variable is
mode = "last", this observation is chosen while for
mode = "first"the observation is chosen only if there are no observations where the variable is not 'NA'.
Permitted Values: list of variables or
desc(<variable>)function calls created by
Prefix used for the output variable(s).
A character scalar is expected. For the date variable "DT" is appended to the specified prefix and for the date imputation flag "DTF". I.e., for
new_vars_prefix = "AST"the variables
Filter for additional dataset (
Only observations fulfilling the specified condition are taken into account for merging. If the argument is not specified, all observations are considered.
Permitted Values: a condition
Determines if the first or last observation is selected. If the
orderargument is specified,
modemust be non-null.
orderargument is not specified, the
modeargument is ignored.
'--DTC'date to impute
A character date is expected in a format like
yyyy-mm-ddThh:mm:ss. Trailing components can be omitted and
-is a valid "missing" value for any component.
The value to impute the day/month when a datepart is missing.
A character value is expected, either as a
format with month and day specified as
"06-15"for the 15th of June (The year can not be specified; for imputing the year
max_datesargument can be used (see examples).),
or as a keyword:
"last"to impute to the first/mid/last day/month.
The argument is ignored if
highest_imputationis less then
Whether the date imputation flag must also be derived.
"auto"is specified, the date imputation flag is derived if the
date_imputationargument is not null.
A list of dates is expected. It is ensured that the imputed date is not before any of the specified dates, e.g., that the imputed adverse event start date is not before the first treatment date. Only dates which are in the range of possible dates of the
dtcvalue are considered. The possible dates are defined by the missing parts of the
dtcdate (see example below). This ensures that the non-missing parts of the
dtcdate are not changed. A date or date-time object is expected. For example
impute_dtc_dtm( "2020-11", min_dates = list( ymd_hms("2020-12-06T12:12:12"), ymd_hms("2020-11-11T11:11:11") ), highest_imputation = "M" )
"2020-11-11T11:11:11"because the possible dates for
"2020-12-06T12:12:12"is ignored. Returning
"2020-12-06T12:12:12"would have changed the month although it is not missing (in the
A list of dates is expected. It is ensured that the imputed date is not after any of the specified dates, e.g., that the imputed date is not after the data cut off date. Only dates which are in the range of possible dates are considered. A date or date-time object is expected.
Preserve day if month is missing and day is present
preserve = TRUE(and
date_imputation = "MID").
"error"is specified, the specified message is issued if the observations of the (restricted) additional dataset are not unique with respect to the by variables and the order.
Message of unique check
If the uniqueness check fails, the specified message is displayed.
paste("Dataset `dataset_add` contains duplicate records with respect to", enumerate(vars2chr(by_vars)))
The output dataset contains all observations and variables of the
input dataset and additionally the variable
optionally the variable
<new_vars_prefix>DTF derived from the additional
The additional dataset is restricted to the observations matching the
The date variable and if requested, the date imputation flag is added to the additional dataset.
orderis specified, for each by group the first or last observation (depending on
mode) is selected.
The date and flag variables are merged to the input dataset.