In SAS, how can I calculate age from the date-of-birth data?
SAS provides the DATE() and MDY()
functions to calculate age. In SAS, date type variables contain the
number of days between January 1, 1960, and the date specified. To
compute age using a date of birth and the current date, use the
following code:
The floor function takes the integer part of age for
colloquial usage, but does not take into account the effect of leap
years. To avoid this problem, use the intck function by
replacing age = floor(days / 365); in the above code with:
age = floor ((intck('month',birthday,today) - (day(today) < day(birthday))) / 12);
The input format MMDDYY6. specifies month, day, and year
in six digits. You can also use other formats, such as
MMDDYY8. (e.g., 12/31/68,
12-31-68, 12.31.68, or
12311968), DDMMYY6., and
DDMMYY8..
DATE() returns the current date set in the computer. To
specify a particular day, use the MDY() function as
follows:
For more information about accurately calculating age in SAS, see the SAS knowledge base document Accurately Calculating Age with Only One Line of Code.
For more information about statistical and mathematical software, email the UITS Stat/Math Center, visit the center's web page, or phone 812-855-4724 (IUB) or 317-278-4740 (IUPUI). The center is located in Bloomington at 410 N. Park Avenue, and is open for consultation by appointment Monday-Friday 9am-5pm.
Also see:
- In SAS, how do I create an ASCII text file from a SAS data set?
- How do I use SAS if I'm not running the X Window System?
- During a SAS session, how do I redirect the work files?
- In SAS, how can I assign serial numbers to observations in a data set?
- In SAS, how can I randomly select a certain number of observations from a dataset?
- In SAS, how can I make my output more readable?
- In SAS, how do I create a permanent SAS data file?
- In SAS, how do I remove observations?
Last modified on July 25, 2008.






