Query to add the age of the individuals at a certain date
Source:R/addDemographicsQuery.R
addAgeQuery.Rd
`r lifecycle::badge("experimental")` Same as `addAge()`, except query is not computed to a table.
Usage
addAgeQuery(
x,
indexDate = "cohort_start_date",
ageName = "age",
ageGroup = NULL,
ageMissingMonth = 1,
ageMissingDay = 1,
ageImposeMonth = FALSE,
ageImposeDay = FALSE,
missingAgeGroupValue = "None"
)
Arguments
- x
Table with individuals in the cdm.
- indexDate
Variable in x that contains the date to compute the age.
- ageName
Name of the new column that contains age.
- ageGroup
List of age groups to be added.
- ageMissingMonth
Month of the year assigned to individuals with missing month of birth. By default: 1.
- ageMissingDay
day of the month assigned to individuals with missing day of birth. By default: 1.
- ageImposeMonth
Whether the month of the date of birth will be considered as missing for all the individuals.
- ageImposeDay
Whether the day of the date of birth will be considered as missing for all the individuals.
- missingAgeGroupValue
Value to include if missing age.
Examples
# \donttest{
cdm <- mockPatientProfiles()
cdm$cohort1 |>
addAgeQuery()
#> # Source: SQL [10 x 5]
#> # Database: DuckDB v1.1.1 [unknown@Linux 6.5.0-1025-azure:R 4.4.1/:memory:]
#> cohort_definition_id subject_id cohort_start_date cohort_end_date age
#> <int> <int> <date> <date> <int>
#> 1 2 10 1963-10-25 1963-10-26 29
#> 2 2 9 1967-12-01 1968-06-23 19
#> 3 2 5 1934-04-10 1937-03-23 27
#> 4 3 8 1958-04-13 1963-06-18 22
#> 5 1 6 1917-04-28 1919-11-25 7
#> 6 1 4 1972-07-27 1986-04-07 28
#> 7 1 2 1956-09-06 1957-10-01 1
#> 8 2 1 1938-03-13 1944-04-07 26
#> 9 2 3 1964-11-04 1967-06-11 6
#> 10 1 7 1932-01-20 1937-10-27 6
mockDisconnect(cdm = cdm)
# }