Konrad
Konrad

Reputation: 18595

Understanding Intnx statement in SAS

It's been a while since I have done anything in SAS, I'm going through some legacy code where I found the following statement in data step:

variable_month = Intnx("Month",some_date,0,"B");

According to the documentation Intnx:

Increments a date, time, or datetime value by a given time interval, and returns a date, time, or datetime value.

However, when I try to run the following code:

data _null_;
    *Mirror SAS code statement;
    date1=Intnx('Month', '01aug11:00:10:48'dt, 0, "B");
    put 'Results   ' date1= datetime19. ;
run;

I'm getting error message:

NOTE: Invalid argument to function INTNX('Month',1627776648,0,'B') at line 30 column 8.

Question

What was the aim behind the original Intnx statement? To get the month from date?

Upvotes: 1

Views: 523

Answers (1)

Reeza
Reeza

Reputation: 21274

You're mixing up datetimes and dates.

The original code would have aligned a date to the beginning of the month. You used an interval of month but provided a datetime value not a date value. To use this correctly you would need to use dtMonth as your interval to get the same behaviour. It would align the date to the beginning of the period specified.

date1=Intnx('dtMonth', '01aug11:00:10:48'dt, 0, "B");

Upvotes: 3

Related Questions