For the data, you can run in SAS: data py1; input dob :ddmmyy10. sdate :ddmmyy10. edate :ddmmyy10. id ageatstart ageatend py ; format dob ddmmyy10. sdate ddmmyy10. edate ddmmyy10.; datalines; 05/03/1980 01/01/2005 31/12/2014 1 24 34 10.0 12/08/2006 12/08/2006 31/12/2014 2 0 8 8.39 19/09/1975 01/01/2005 20/12/2011 3 29 35 6.38 ; run; The confusion re. age groups was due to me giving examples where different cutoff thresholds were used for organising the age group. Obviously, age groups will be organised as consecutive groups (without any overlap); so let's agree that the desired arrangement for age groups should be: agegrp1: <20; agegrp2: [20-29]; agegrp3: [30,39]; and agegrp4: >=40.
... View more