简体   繁体   中英

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.

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.

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.

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. It may display 01JAN2014 but it represents a number, so you can still perform computations.

If you store the date as a SAS date, you can use the function intnx to increment it by whatever period you like.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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