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 birthyearmonth with the value format YYYYMM.

//Connect to databank
require no.ssb.fdb:1 as fdb1

create-dataset demografidata
import fdb1/BEFOLKNING_FOEDSELS_AAR_MND as birthyearmonth

//Calculate age measured in 2000 by using birthdate (YYYYMM) 
generate age = 2000 - int(birthyearmonth / 100)