簡體   English   中英

查找兩個日期之間的天數間隔 SAS

[英]Find the interval in days between two dates SAS

我試圖找出兩個日期之間的天數,但我只得到一些點來代替天數列中的天數。 該文件如下:

Start date  End date
7/5/2020    7/9/2020
7/12/2020   9/1/2020
7/27/2020   7/29/2020
7/11/2020   7/12/2020
7/15/2020   7/22/2020
7/16/2020   7/23/2020

使用此代碼:

DATA Dataset;set Dataset;
Format Start_date mmddyy8.;  
Format End_date mmddyy8.; /*The type of the two variables is Char and the format is MMDDYY after using the format code line*/
Days=INTCK('day', Start_date , End_date);
run;

Proc print data=Dataset;

我得到:

Start_date   End_date   Days
7/5/20         7/9/20   .
7/12/20        9/1/20   .
7/27/20       7/29/20   .
7/11/20       7/12/20   .
7/15/20       7/22/20   .
7/16/20       7/23/20   .

拜托,如果可能的話,有人可以幫助我嗎? 先感謝您。

您不能使用格式語句更改變量類型。 您需要使用輸入並轉換變量然后執行操作。

DATA Dataset1;*do not use the same data set name, it makes it harder to find errors;
set Dataset;
*convert to SAS dates;
start_date_num = input(start_date, mmddyy10.);
end_date_num = input(end_date, mmddyy10.);
format start_date_num end_date_num date9.;

*take the difference;
Days=end_date_num - start_date_num;

run;

Proc print data=Dataset1;
run;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM