Extract parts from numerical values

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

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

create-dataset demografidata
import BEFOLKNING_FOEDSELS_AAR_MND as faarmnd

//Calculate age measured in 2000 by using birthdate (YYYYMM) 

generate alder = 2000 - int(faarmnd / 100)