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

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