Skip to contents

Derives analysis age (AAGE) and analysis age unit (AAGEU)

Usage

derive_vars_aage(
  dataset,
  start_date = BRTHDT,
  end_date = RANDDT,
  unit = "years"
)

Arguments

dataset

Input dataset

The columns specified by the start_date and the end_date parameter are expected.

start_date

The start date

A date or date-time object is expected.

Refer to derive_vars_dt() to impute and derive a date from a date character vector to a date object.

Default: BRTHDT

end_date

The end date

A date or date-time object is expected.

Refer to derive_vars_dt() to impute and derive a date from a date character vector to a date object.

Default: RANDDT

unit

Unit

The age is derived in the specified unit

Default: 'years'

Permitted Values: 'years', 'months', 'weeks', 'days', 'hours', 'minutes', 'seconds'

Value

The input dataset with AAGE and AAGEU added

Details

The age is derived as the integer part of the duration from start to end date in the specified unit. When 'years' or 'months' are specified in the out_unit parameter, because of the underlying lubridate::time_length() function that is used here, results are calculated based on the actual calendar length of months or years rather than assuming equal days every month (30.4375 days) or every year (365.25 days).

See also

Examples

library(tibble)
library(lubridate)

data <- tribble(
  ~BRTHDT, ~RANDDT,
  ymd("1984-09-06"), ymd("2020-02-24")
)

derive_vars_aage(data)
#> # A tibble: 1 x 4
#>   BRTHDT     RANDDT      AAGE AAGEU
#>   <date>     <date>     <dbl> <chr>
#> 1 1984-09-06 2020-02-24    35 YEARS