Extract parts from numerical values

The int() function can be used to extract parts from numerical values. It rounds downwards to nearest integer number. Alternatively the floor() function may be used.

This example demonstrates how to generate age per 2021 from the variable birthdate with the numerical value format YYYYMM.

//Connect to datastore
require no.ssb.fdb:23 as db

create-dataset demography
import db/BEFOLKNING_FOEDSELS_AAR_MND as birthdate

//Calculate age in 2021 from birthdate 
generate age = 2021 - int(birthdate / 100)