Duration between two dates in SAS

I will explain in an example -

Suppose I have two dates and I want to find the duration between them in the month of month format.

start date= 19940412
end date= 20120326

      

the duration of this is 17 years 11 months 14 days.

So what code am I writing to get this result in sas?

+3


source to share


2 answers


Here is the code you need:

data _null_;
   start_date= '19940412';
   end_date= '20120326';
   /* convert to sas dates */
   start_dt=input(start_date,yymmdd8.);
   end_dt=input(end_date,yymmdd8.);
   /* calculate difference in years */
   years=intck('YEAR',start_dt,end_dt,'C');
   /* recalculate start date */
   start_dt=intnx('YEAR',start_dt,years,'S');
   /* calculate remaining months */
   months=intck('MONTH',start_dt,end_dt,'C');
   /* recalculate start date */
   start_dt=intnx('MONTH',start_dt,months,'S');
   /* calculate remaining days */
   days=intck('DAY',start_dt,end_dt,'C');
   /* results */
   put years= months= days=;
run;

      



What gives:

years=17 months=11 days=14

      

+3


source


You can use SAS INTCK function

See online for details



 sas function intck

      

-1


source







All Articles