Bob
Bob

Reputation: 121

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.

Upvotes: 0

Views: 19861

Answers (2)

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');

Upvotes: 0

Joe
Joe

Reputation: 63424

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.

Upvotes: 5

Related Questions