BookmarkSubscribeRSS Feed
My_SAS
Calcite | Level 5

actually i am having a joining date i want to find how many years he was wroking to till date

data l;
sdate='12jan2010'd;
enddate=today()
Tot=yrdif(sdate, edate, 'ACT/365');
run;

But i wnat the output like this how many years,months and days to till date.

sdate          Years  Months days
12jan2010      2      2            3

1 REPLY 1
Keith
Obsidian | Level 7

Here is a link to a useful article on the SAS website on how to calculate age from date of birth.

http://support.sas.com/kb/24/808.html

I've used this technique to answer your question, first of all I've calculated the total number of complete months between the 2 dates and then used this to get the values you need (years is the integer part of total_months/12, months is the remainder of total_months/12, days is the difference between the end date and the start date advanced by total_months.

data l;

format sdate enddate date9.;

sdate='12jan2010'd;

enddate=today();

_totmonths=intck('month',sdate,enddate)-(day(enddate)< day(sdate));

years=floor(_totmonths/12);

months=mod(_totmonths,12);

days=enddate-intnx('month',sdate,_totmonths,'S');

drop _totmonths;

run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 1 reply
  • 704 views
  • 0 likes
  • 2 in conversation