我尝试按以下方式使用 INTCK 但出现错误。我不确定我做错了什么。我将不胜感激你的帮助。谢谢。
PROC FORMAT;
PICTURE DTFMT LOW-HIGH='%0m/%0d/%Y' (DATATYPE=DATETIME);
RUN;
data want;
dt_val1='17JUL2006:00:00:00.000'dt;
dt_val2='17AUG2012:00:00:00.000'dt;
format dt_val1 dt_val2 dt_val3 dtfmt.;
dt_val3=intck('MONTH',dt_val1,dt_val2);
put dt_val3;
run;
最佳答案
了解 SAS 中日期和日期时间值之间的差异非常重要。本网站和其他网站经常对此进行报道。这是official documentation以及摘录。
SAS date value is a value that represents the number of days between January 1, 1960, and a specified date.
SAS time value is a value representing the number of seconds since midnight of the current day. SAS time values are between 0 and 86400.
SAS datetime value is a value representing the number of seconds between January 1, 1960, and an hour/minute/second within a specified date.
它们不能互换使用,但您可以在它们之间进行转换。看来您应该在此应用程序中使用日期变量。这可能会让你的事情变得更容易一些。
将日期转换为日期时间很容易,而将日期时间值转换为日期则更容易:
dateval = datepart(dtval);
也就是说,您的 intck
函数可能会抛出错误,因为“MONTH”是日期间隔而不是日期时间间隔。使用“DTMONTH”可能会起作用。请看这个link了解更多详情。
关于datetime - sas:无法找出 INTCK 函数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17192790/