ARCHIVED: In SAS, how can I calculate age from the date-of-birth data?
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:
DATA birth; INPUT id birthday MMDDYY6.; today = DATE(); days = today - birthday; age = floor(days / 365); DATALINES; 01 122275 02 010865 03 030586 . . RUN;
The input format
MMDDYY6. specifies month, day, and year
in six digits. You can also use other formats, such as
DATE() returns the current date set in the computer. To
specify a particular day, use the
MDY() function as
today = MDY(03,31,2008);
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
age = floor(days / 365); in the above code with:
age = floor ((intck('month',birthday,today) - (day(today) < day(birthday))) / 12);
intck function will correct for leap years. The
first part of the command,
returns the number of times the first day of a month is passed between
birthday and today. To correct for the number of times the same day
of the starting month has passed, the logical test
day(birthday)) is used, resulting in a value of 0 or 1 to be
subtracted from the initial calculation of months. Finally, the
corrected number of months is divided by 12 and rounded to produce the
If you have questions about using statistical and mathematical software at Indiana University, contact Research Analytics. Research Analytics is located on the IU Bloomington campus at Woodburn Hall 200; staff are available for consultation Monday-Friday 9am-noon and by appointment.
This is document aczw in the Knowledge Base.
Last modified on 2015-06-26 00:00:00.
- Fill out this form to submit your issue to the UITS Support Center.
- Please note that you must be affiliated with Indiana University to receive support.
- All fields are required.