SAS 中两个日期之间的持续时间 [英] Duration between two dates in SAS
本文介绍了SAS 中两个日期之间的持续时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我会通过一个例子来解释-
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
这 17 年 11 个月 14 天的持续时间.
duration of this 17 years 11 months 14 days.
那么我写什么代码才能在 sas 中得到这个结果?
So what code do i write to get this result in sas?
推荐答案
这是您需要的代码:
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;
给出:
years=17 months=11 days=14
这篇关于SAS 中两个日期之间的持续时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文