简体   繁体   English

SAS日期和减去1个月

[英]SAS Date and substracting 1 Month

I have a date that is stored as a number that is 201401. I would like to subtract 1 month, so that is 201312 and not 201400. 我有一个存储为201401的日期。我想减去1个月,所以是201312,而不是201400。

Also, if there is a more efficient way, please suggest as well. 另外,如果有更有效的方法,也请提出建议。 I also have the date stored as 01Jan2014, and would be fine converting the SAS date at that point, so that I can create two new columns (with 1 month subtracted) so that they have the value 01Dec2013 and 201312. Also, a function for incrementing the month forward or backward would be much appreciated. 我还将日期存储为01Jan2014,可以很好地转换SAS日期,以便可以创建两个新列(减去1个月),使其具有值01Dec2013和201312。向前或向后增加月份将不胜感激。

Thanks in advance. 提前致谢。

If you store the date as a SAS date, you can use the function intnx to increment it by whatever period you like. 如果将日期存储为SAS日期,则可以使用函数intnx将其递增任意时间。

newdate = intnx('Month',olddate,1,'s');

If you store it as an integer like your original, you're on your own to figure that out. 如果将其存储为与原始整数一样的整数,则需要您自己弄清楚。 My answer: don't. 我的回答是:不要。

The prior answer works. 先前的答案有效。 I just wanted to add, storing as Date in SAS is not the same as storing as integer. 我只想添加,在SAS中作为日期存储与作为整数存储不同。 It may display 01JAN2014 but it represents a number, so you can still perform computations. 它可能显示01JAN2014,但它代表一个数字,因此您仍然可以执行计算。

If you store the date as a SAS date, you can use the function intnx to increment it by whatever period you like. 如果将日期存储为SAS日期,则可以使用函数intnx将其递增任意时间。

newdate = intnx('Month',olddate,1,'s'); newdate = intnx('Month',olddate,1,'s');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM