/*******************************************************************
  This command file for SAS demonstrates how to use dates in a SAS
  data step.

********************************************************************/

options linesize=72 pagesize=58;
title;

data dates;

  length name $12;
  input name $ b_mon b_day b_yr int_mon int_day int_yr;

  if b_day = . then b_day = 15;
  if int_day = . then int_day = 15;

  birdate = mdy(b_mon,b_day,b_yr);
  intdate = mdy(int_mon,int_day,int_yr);
  intage = int((intdate-birdate)/365);

  cards;

  Arthur   12 12 84  9 3  94
  Samantha 1  20 85  9 15 94
  Bruce    10 6  83  10 2 94
  Boggy    4  17 82  10 5 94
  Nicole   6  .  83  9 14 94
  ;

proc print data=dates;
  title 'printing dates as number of days since Jan 1, 1960';

run;
proc print data=dates;
  format birdate mmddyy8. intdate mmddyy8.;
  title 'printing dates using date formats';
run;

The output from this program is shown below:

           printing dates as number of days since Jan 1, 1960


                                    I     I            B       I
                                    N     N     I      I       N       I
                  B     B           T     T     N      R       T       N
        N         _     _     B     _     _     T      D       D       T
O       A         M     D     _     M     D     _      A       A       A
B       M         O     A     Y     O     A     Y      T       T       G
S       E         N     Y     R     N     Y     R      E       E       E

1    Arthur      12    12    84     9     3    94    9112    12664     9
2    Samantha     1    20    85     9    15    94    9151    12676     9
3    Bruce       10     6    83    10     2    94    8679    12693    10
4    Boggy        4    17    82    10     5    94    8142    12696    12
5    Nicole       6    15    83     9    14    94    8566    12675    11


                   printing dates using date formats                  
1

                                I    I               B          I
                                N    N    I          I          N       I
                 B    B         T    T    N          R          T       N
        N        _    _    B    _    _    T          D          D       T
 O      A        M    D    _    M    D    _          A          A       A
 B      M        O    A    Y    O    A    Y          T          T       G
 S      E        N    Y    R    N    Y    R          E          E       E

 1   Arthur     12   12   84    9    3   94   12/12/84   09/03/94       9
 2   Samantha    1   20   85    9   15   94   01/20/85   09/15/94       9
 3   Bruce      10    6   83   10    2   94   10/06/01   10/02/94      93
 4   Boggy       4   17   82   10    5   94   04/17/82   10/05/94      12
 5   Nicole      6   15   83    9   14   94   06/15/83   09/14/94      11