我有一个数据集,有一个名为date的变量。 它看起来像“31MAY13:00:00:00”,其数据类型是日期。 现在我想创建一个新变量,使其成为相应月份的第一天。 所以对于“31MAY13:00:00:00”,它会给我“01MAY13:00:00:00”。 这是我的代码:
DATA newdata; SET olddata; newvariable = INTNX('month',olddate,0,"B"); RUN;日志说:函数INTNX的参数2无效。 我和SAS合作已经有一段时间了。 任何想法? 非常感谢!
I have a dataset and there is a variable called date. It looks like "31MAY13:00:00:00" and its datatype is date. Now I want to create a new variable such that it is the first day of the corresponding month. So for "31MAY13:00:00:00", it will give me "01MAY13:00:00:00". Here's my code:
DATA newdata; SET olddata; newvariable = INTNX('month',olddate,0,"B"); RUN;The log says: Argument 2 to function INTNX is invalid. It's been a while working with SAS for me. Any idea? Thank you so much!
最满意答案
您的值是日期时间,而不是日期。 您需要将dt添加到区间的前面,以增加日期时间值:
DATA newdata; SET olddata; newvariable = INTNX('dtmonth',olddate,0,"B"); RUN;Your value is a datetime, not a date. You need to add dt to the front of the interval like this to increment a datetime value:
DATA newdata; SET olddata; newvariable = INTNX('dtmonth',olddate,0,"B"); RUN;更多推荐
发布评论