3x89g2
3x89g2

Reputation: 257

"Invalid 2nd argument" when using INTNX in 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!

Upvotes: 0

Views: 839

Answers (2)

in_user
in_user

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

DWal
DWal

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

Related Questions