The intnx function increments dates by intervals. It computes the date (or datetime) of the start of each interval. For example, let's suppose that you had a column of days of the month, and you wanted to create a new variable that was the first of the next month. You could use the intnx function to help you create your new variable.
The syntax of the intnx function is: intnx(interval, from, n <, alignment>), where interval is a character (e.g., string) constant or variable, from is the starting value (either a date or datetime), n is the number of intervals to increment, and alignment is optional and controls the alignment of the dates.
data temp2; input id 1 @3 date mmddyy11.; cards; 1 11/12/1980 2 10/20/1996 3 12/21/1999 ; run; proc print data = temp2; format date date9.; run;id date 1 12NOV1980 2 20OCT1996 3 21DEC1999data temp3; set temp2; new_month = intnx('month',date,1); run; proc print data = temp3 noobs; format date new_month date9.; run;id date new_month 1 12NOV1980 01DEC1980 2 20OCT1996 01NOV1996 3 21DEC1999 01JAN2000
Now let's try another example, this time creating a variable that is two days later than the day given in our data set.
data temp3a; set temp2; two_days = intnx('day',date,2); run; proc print data = temp3a noobs; format date two_days date9.; run;id date two_days 1 12NOV1980 14NOV1980 2 20OCT1996 22OCT1996 3 21DEC1999 23DEC1999
The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California.