BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
robertrao
Quartz | Level 8

Hi I am trying to find the years between the two dates.

date1                    date2

16MAR2011     10JAN1964

difference=date1-date2

this gives me in seconds....

How can I get years??????

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
stat_sas
Ammonite | Level 13

Not sure, I am using the same and getting 47.

data have;

date1='16MAR2011'd;                  

date2='10JAN1964'd;

difference=intck('year',date2,date1);

run;

View solution in original post

10 REPLIES 10
stat_sas
Ammonite | Level 13

data have;

date1='16MAR2011'd;                  

date2='10JAN1964'd;

difference=intck('year',date2,date1);

run;

robertrao
Quartz | Level 8

difference=intck('year',date2,date1);

I tried the above and it gives me negative age in years

Do I need to do:

difference=intck('year',date1,date2);

Thanks

stat_sas
Ammonite | Level 13

What is your date1?

robertrao
Quartz | Level 8

date1=16MAR2011

date2=10JAN1964

stat_sas
Ammonite | Level 13

Not sure, I am using the same and getting 47.

data have;

date1='16MAR2011'd;                  

date2='10JAN1964'd;

difference=intck('year',date2,date1);

run;

ballardw
Super User

Your order is different the OP.

ballardw
Super User

If that gives seconds you have DATETIME value, it should be Days if the values are actual SAS dates.

Do you need years as in and date in 2011 and any date in 1964 = 47 or do you need to calculate as if a calendar age?

robertrao
Quartz | Level 8


Hi Ballard,

I have SAS dates and not datetimes. sorry for the confusion.

I think if we can get to the 47 that should be fine

also please let me know how to do the calendar age ....good to know

Thanks

Ksharp
Super User

difference=yrdif (date2,date1);

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 10 replies
  • 996 views
  • 6 likes
  • 5 in conversation