Sample 24567: Calculate a person's age
The sample code on the Full Code tab illustrates how to determine a person's current age using their date of birth.
Note: This is Example 6.11 from Combining and Modifying SAS Data Sets - Examples.
Link to another note about calculating age:
Sample 36788: Calculating a person's age using PROC FCMP
In SAS 9.2, a fifth argument to the INTCK function was added which will also help calculate a person's age. In SAS 9.2, the argument is called 'alignment', but it was changed to 'method' in SAS 9.3. Below is a link to the SAS 9.3 documentation because it contains a more detailed explanation about the argument than the SAS 9.2 documentation. Click here to go to the documentation
          These sample files and code examples are provided by SAS Institute
          Inc. "as is" without warranty of any kind, either express or implied, including
          but not limited to the implied warranties of merchantability and fitness for a
          particular purpose. Recipients acknowledge and agree that SAS Institute shall
          not be liable for any damages whatsoever arising out of their use of this material.
          In addition, SAS Institute will provide no support for the materials contained herein.
        
 
/* Create sample data */
data birth;
  input name $ bday :mmddyy10.;
datalines;
Miguel      12/31/1973
Joe         02/28/1976
Rutger      03/29/1976
Broguen     03/01/1976
Susan       12/12/1976
Michael     02/14/1971
LeCe        11/09/1967
Hans        07/02/1955
Lou         07/30/1960
;
/* Use the INTCK function to count the number of months between       */
/* the date of birth and the current date.  Divide the number of      */
/* months by 12 to produce the number of years.  Use the MONTH        */
/* function to determine if the month of the birthday and the current */
/* date are the same.  If they are, determine if the birthday has     */
/* occurred this year.  If it hasn't, adjust the age by subtracting   */
/* one year.                                                          */  
data ages;
  set birth;
  retain current;
  if _n_=1 then current=today();
  format bday current worddate20.;
  age=int(intck('month',bday,current)/12);
  if month(bday)=month(current) then age=age-(day(bday)>day(current));
run;
proc print;
run;
          These sample files and code examples are provided by SAS Institute
          Inc. "as is" without warranty of any kind, either express or implied, including
          but not limited to the implied warranties of merchantability and fitness for a
          particular purpose. Recipients acknowledge and agree that SAS Institute shall
          not be liable for any damages whatsoever arising out of their use of this material.
          In addition, SAS Institute will provide no support for the materials contained herein.
        
 
Obs    name                       bday                 current    age
  1    Miguel        December 31, 1973       December 14, 2004     30
  2    Joe           February 28, 1976       December 14, 2004     28
  3    Rutger           March 29, 1976       December 14, 2004     28
  4    Broguen           March 1, 1976       December 14, 2004     28
  5    Susan         December 12, 1976       December 14, 2004     28
  6    Michael       February 14, 1971       December 14, 2004     33
  7    LeCe           November 9, 1967       December 14, 2004     37
  8    Hans               July 2, 1955       December 14, 2004     49
  9    Lou               July 30, 1960       December 14, 2004     44
 
Determine a person's current age using their date of birth.
| Type: | Sample | 
| Topic: | SAS Reference  ==>  Functions  ==>  Date and Time SAS Reference  ==>  DATA Step
  | 
| Date Modified: | 2011-12-22 13:22:43 | 
| Date Created: | 2004-09-30 14:08:54 | 
Operating System and Release Information
| SAS System | Base SAS | All | n/a | n/a |