Duration between two dates in SAS

馋奶兔 提交于 2019-12-31 01:48:06

问题


I will explain through an example-

suppose I have two dates and I want to find the duration between them in years month date format

start date= 19940412
end date= 20120326

duration of this 17 years 11 months 14 days.

So what code do i write to get this result in sas?


回答1:


Here's 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;

Which gives:

years=17 months=11 days=14



回答2:


You can use the SAS function INTCK

For details, just search the internet for

 sas function intck


来源:https://stackoverflow.com/questions/27056083/duration-between-two-dates-in-sas

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!