|
> -----Original Message-----
> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On
> Behalf Of Fehd, Ronald J. (CDC/CCHIS/NCPHI)
> Sent: Monday, May 18, 2009 3:46 PM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: Re: SUGI 17 and datediff function
>
> I have harvested this macro
> and its test program
>
> http://www.sascommunity.org/wiki/Macro_DateDiff
>
> however, I do not have the time to debug it.
>
> the loop is terminating at one observation
> and it should output 4 obs.
>
> to you: SAS-L
>
> Ron Fehd the macro maven CDC Atlanta GA USA RJF2 at cdc dot gov
Ron,
I think the loop should produce 35 iterations, since start date is May 27
and end date is June 30. In addition, I don't find the distinction between
"mathematical" and "intuitive" particularly useful. I know these are not
your distinctions, they are from the paper. Since months have varying
numbers of days, calling the "mathematical" more accurate because it is
based on an average number of days per month doesn't make it more accurate.
From my perspective, the "intuitive" apporach is both accurate and, well,
more intuitive. :-)
The following is a more compact macro for calculating the "intuitive"
calculation of years, months, and days between two dates. It should run
fine at least on SAS 8 and 9. I haven't commented it thoroughly, or put in
place any error checking. If anyone wants to do that, be my guest. I am
sure it could also be made more efficient. The guts of the calculations are
based on the well known calculation of age formulated by Billy Kreuter.
%macro diff_date(begin = ,
end = today(),
y = years,
m = months,
d = days
);
*--number of full months between dates;
&m = intck('month', &begin, &end)-(day(&end) < day(&begin));
*--number of full years between dates;
&y = floor(&m / 12);
*--remainder of full months after removing full years;
&m = mod(&m , 12);
*--number of days remaining after removing years and months;
&d = (day(&end) < day(&begin)) * day(intnx('month',&begin,1)-1) +
day(&end) - day(&begin);
%mend;
data _null_;
begin_date = '31jan2008'd;
end_date = '01mar2009'd;
%diff_date(begin=begin_date, end=end_date)
put years= months= days= ;
run;
Hope this is useful,
Dan
Daniel Nordlund
Bothell, WA USA
|