/************************************************************************** Goal: To be able to calculate current age in several different units. Strategy: Obtain current datetime with datetime function. Then either convert from elapsed seconds to some other unit or use the intck function to find the number of intervals. Documentation: "SAS Language, Reference, Version 6, First Edition", Pages 128-131, Ch. 11 "Combining and Modifying SAS Datasets, Examples", Pages 172-173 ***************************************************************************/ data test; input eventdt datetime.; /* date and time of event */ curdt=datetime(); /* current date and time */ seconds=curdt-eventdt; /* find elapsed seconds * age=seconds/(365.25*24*60*60); /* convert from seconds to years */ /* see Combining and Modifying SAS Datasets */ exactage=int(intck('dtmonth',eventdt,curdt)/12); if month(datepart(eventdt))=month(datepart(curdt)) then exactage=exactage-(day(datepart(eventdt))>day(datepart(curdt))); /* If you need to calculate late fee for unpaid silver spoon by months, calculate elapsed months as follows. Note: the intck function counts the number of times the time interval starts. This works great if your billing cycle begins at the beginning of the month. */ months=intck('dtmonth',eventdt,curdt); cards; 10oct1972:03:45:13.2 15nov1996:00:00:00.0 01jan1960:00:00:00.0 15nov2096:00:00:00.0 ; proc print label;run;