DATA Step, Macro, Functions and more

DATDIF function

Accepted Solution Solved
Reply
Contributor
Posts: 66
Accepted Solution

DATDIF function

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.


Accepted Solutions
Solution
‎07-26-2011 01:44 PM
Contributor
Posts: 66

DATDIF function

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

View solution in original post


All Replies
Super User
Posts: 19,770

DATDIF function

Posted in reply to Danglytics

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.

PROC Star
Posts: 7,468

DATDIF function

Posted in reply to Danglytics

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

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

Contributor
Posts: 66

DATDIF function

I've tried

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

but i'm still getting the error.

Super User
Posts: 19,770

DATDIF function

Posted in reply to Danglytics

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

Solution
‎07-26-2011 01:44 PM
Contributor
Posts: 66

DATDIF function

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

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 1160 views
  • 3 likes
  • 3 in conversation