derive_vars_aage {admiral} | R Documentation |

## Derive Analysis Age

### Description

Derives analysis age (`AAGE`

) and analysis age unit (`AAGEU`

).

**Note:** This is a wrapper function for the more generic `derive_vars_duration()`

.

### Usage

```
derive_vars_aage(
dataset,
start_date = BRTHDT,
end_date = RANDDT,
age_unit = "YEARS",
type = "interval"
)
```

### Arguments

`dataset` |
Input dataset The variables specified by the |

`start_date` |
The start date A date or date-time object is expected. Refer to Default: |

`end_date` |
The end date A date or date-time object is expected. Refer to Default: |

`age_unit` |
Age unit The age is derived in the specified unit Permitted Values (case-insensitive): For years: For months: For weeks: For days: For hours: For minutes: For seconds: |

`type` |
lubridate duration type. See below for details. Default: Permitted Values: |

### Details

The duration is derived as time from start to end date in the specified output unit. If the end date is before the start date, the duration is negative. The start and end date variable must be present in the specified input dataset.

The lubridate package calculates two types of spans between two dates: duration and interval. While these calculations are largely the same, when the unit of the time period is month or year the result can be slightly different.

The difference arises from the ambiguity in the length of `"1 month"`

or
`"1 year"`

.
Months may have 31, 30, 28, or 29 days, and years are 365 days and 366 during leap years.
Durations and intervals help solve the ambiguity in these measures.

The **interval** between `2000-02-01`

and `2000-03-01`

is `1`

(i.e. one month).
The **duration** between these two dates is `0.95`

, which accounts for the fact
that the year 2000 is a leap year, February has 29 days, and the average month
length is `30.4375`

, i.e. `29 / 30.4375 = 0.95`

.

For additional details, review the lubridate time span reference page.

### Value

The input dataset with `AAGE`

and `AAGEU`

added

### See Also

ADSL Functions that returns variable appended to dataset:
`derive_var_age_years()`

,
`derive_vars_extreme_event()`

,
`derive_vars_period()`

### Examples

```
library(tibble)
library(lubridate)
data <- tribble(
~BRTHDT, ~RANDDT,
ymd("1984-09-06"), ymd("2020-02-24")
)
derive_vars_aage(data)
```

*admiral*version 1.1.1 Index]