[英]Duration between two dates in SAS
我將通過一個例子來解釋——
假設我有兩個日期,我想以年月日期格式找到它們之間的持續時間
start date= 19940412
end date= 20120326
工期17年11個月14天。
那么我寫什么代碼才能在 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 函數 INTCK
詳情請上網搜索
sas function intck
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.