Calcite | Level 5

## converting dates to years

Hi Sas users

I have two dates in the format of mmddyy8. How can I convert these dates to years. See my code below.

data colon.service;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
Meteorite | Level 14

## Re: converting dates to years

Hi @nturne

You can use the INTCK function, which returns the count of the number of interval boundaries between two dates, two
times, or two datetime values.

``````data service;
cards;
01/16/17 12/16/19
;
run;
``````
4 REPLIES 4
Diamond | Level 26

## Re: converting dates to years

admdate-svcdate is the number of days between admdate and svcdate. To get approximate years, you divide by 365 or 365.25. To get exact years accounting for leap years, use the INTCK function or the YRDIF function.

--
Paige Miller
Calcite | Level 5

## Re: converting dates to years

Thank you! The intck function worked.

Super User

## Re: converting dates to years

The YEAR() function wants a date as input.  If you subtract two dates you will get some small number of days which the YEAR() function will then interpret as a date.  So if the difference in days is less than 365 then result will be a date in the year 1960 so applying the YEAR() function to it will return 1960.

How do you want to define the difference in years?  Do you just want to subtract 2015 from 2019?

``number_years=year(admdate)-year(svcdate);``

Do you want to take the difference in days and divide by an average number of days in a year?

``number_years=(admdate-svcdate)/365.25 ;``

Or perhaps you want to use the INTCK() function to count for you.

Meteorite | Level 14

## Re: converting dates to years

Hi @nturne

You can use the INTCK function, which returns the count of the number of interval boundaries between two dates, two
times, or two datetime values.

``````data service;