Tuesday, July 7, 2009

Functions: YRDIF, DATDIF, INTCK

Using YRDIF function:
“act/act” will gives us the actual interval between the two dates.
To know the interval between two dates in Years:

data _null_;
      sdate="12mar1998"d;
      edate="12jun2008"d;
      years=yrdif(sdate,edate,'act/act');
      put years;
run;

Output: 10.2535 yrs


Using DATDIF function:
To know the interval between two dates in Days:

data _null_;
      sdate="12mar1998"d;
      edate="12jun2008"d;
      days=datdif(sdate,edate,'act/act');
      put days;
run;

output: 3745 days


Using the INTCK function:
The INTCK function returns the integer count of the number of intervals in years, months or days between two dates.

data _null_;
      sdate="12mar1998"d;
      edate="12jun2008"d;
      years=intck(‘year’,sdate,edate);
      put years;
run;

output:10 years


To know the interval between 2 dates in days:

data _null_;
      sdate="12mar1998"d;
      edate="12jun2008"d;
      days=intck(‘days’,sdate,edate);
      put days;
run;

result: 3745 days


To know the interval between 2 dates in months:

data _null_;
      sdate="12mar1998"d;
      edate="12jun2008"d;
      months=intck(‘months,sdate,edate);
      put months;
run;

result: 123 months

No comments: