Gangi reddy Gangi reddy - 15 days ago 10
SQL Question

How to create dates from given date to today for every year in SAS?

Here for example give date is 07/04/1992 and today's date is 11/20/2016.

I want output table should be

07/04/1992
07/04/1993
07/04/1994
07/04/1995
07/04/1996
.
.
.
.
07/04/2016


Please help me to get this in SAS.

Leo Leo
Answer

The easiest way to deal with dates is to treat them as such and use the date functions. This version avoids the pitfall of leap years, but (for simplicity) does not address people born February 29.

data want;
    format birth_date mmddyy.;

    dob = mdy(4,7,1992);
    birth_day   = day(dob);
    birth_month = month(dob);
    birth_year  = year(dob);

    end_year = year(today());
    if month(today()) <= month(dob) & day(today()) < day(dob) then
        end_year = end_year - 1;

    do year = birth_year to end_year;
        birth_date = mdy(birth_month,birth_day,year);
        output;
    end;
run;