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

Hi,

I'm trying to get the difference in Years between two dates at the end of each month end date.

MembershipDate: which is a Datetime format and

I have a parameter I reference throughout my code to be the month end date:

%let cur_mth_end = '31Jan10'd. 

I used the function

Tenure = Datdif (MembershipDate, &cur_mth_end, 'act/act') / 365 ;

but I get the note:

Invalid argument to function DatDif

I'm pretty sure its because MembershipDate is a datetime format, but not sure how to fix this.

Thanks for your help.

1 ACCEPTED SOLUTION

Accepted Solutions
Danglytics
Calcite | Level 5

Thanks for your help, I used INTCK to solve it.

View solution in original post

5 REPLIES 5
Reeza
Super User

To convert a datetime to date use the datepart function.

You might want to look up the intck function which calculates some date difference and you can also customize the alignment in that function to 'end' of the month/year which seems what you're looking for.

art297
Opal | Level 21

How about if you wrap MembershipDate within a datepart function?  e.g.

Tenure = Datdif (datepart(MembershipDate), &cur_mth_end, 'act/act') / 365 ;

Danglytics
Calcite | Level 5

I've tried

Tenure = Datdif (datepart(MembershipDate), &cur_mth_end, 'act/act') / 365

but i'm still getting the error.

Reeza
Super User

Post your log, where you're using the mprint option.

Danglytics
Calcite | Level 5

Thanks for your help, I used INTCK to solve it.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 5 replies
  • 2952 views
  • 3 likes
  • 3 in conversation