Reputation: 257
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!
Upvotes: 0
Views: 839
Reputation: 1958
Besides what @Dwal has suggested you could use "datepart" function to extract date and could use the same formula which you had been using.
newvariable = INTNX('month',datepart(olddate),0,"B");
Upvotes: 2
Reputation: 2762
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;
Upvotes: 6