This week’s assignment? Become masters of SAS Functions! Or at least understand the basics of the most popular ones. Chapter 14 is all about Transforming Data with SAS Functions. We decided to divide this chapter in half due to the length of the chapter and things in our study session were going along swimmingly until we hit the interval functions, particularly the INTNX function.

The Prep Guide gives an example for the INTCK function as identifying the 20th anniversary of employment, which clearly demonstrates this functions objective. However, no example is given for the INTNK function in the Prep Guide. The Prep Guide merely states “the INTNK function is similar to the INTCK function. The INTNX function applies multiples of a given interval to a date, time, or datetime value and returns the resulting value.” We clearly needed an example of how the INTNK function would be used.

And who better to ask this question of then functions expert extraordinaire, Ron Cody! Ron just came out with the second edition of SAS Functions by Example. While quickly looking through Ron’s book, I found the following example:

INTNX (‘WEEK’, ‘01JAN1960’d, 1)
Returns:
2 (Sunday, Jan 3, 1960)

I understand that WEEK intervals are counted by Sundays, so I understand why the return date is Sunday, Jan 3. But, where does the preceding 2 come from? I thought that the INTNX function would just return a date and not a numerical value.

We also have a new study partner who found a straightforward explanation of the INTCK and INTNX functions that I thought might be useful to others. “The INTCK function counts the number of intervals between the two dates and returns a number. The INTNX function advances the date or time values by a given interval and returns a date or time value.” Ron’s book reminds us that the “INTCK function counts how many times you cross a boundary going from the start date to the end date.” So, once again, that explains the example above but not why there is a “2” preceding the date. What am I missing?

Until my next blog on:
INTNK (‘week’, ‘25JUN2010’d, 2,)

Share

Sr Associate Development Tester

1. Lets see here:
Intnx and Intck increment thier count when the Begining of a step bound as dictated by the specified Interval is crossed. In the case of your example it is Sunday.
01Jan1960 is a Friday
If you move it forward by one week and since you have left the default of B for the fourth arguement. Yeah you get the 3Jan1960 as your resulting date.
However here is a more interesting one for you two to deliberate:
Data Null ;
Date = IntnX( 'Day90' , '01Jan2000'd , 0 , 'B' ) ;
Put Date= Date9. ;
Run ;

2. Hi Christine,
As Aldous pointed out.The number '2' is the SAS equivalent of Jan,3rd,1960. SAS always stores dates in its equivalent (SAS) values .These equivalent values are nothing but the number of days from Jan,1st 1960 (=0) .Therefore Jan 2nd 1960 =1 ,Jan 3rd 1960 =2 etc .In order for the user to understand what value the SAS date value represents ,we need to format that variable holding that value.For eg consider the small program below:
Data A;
format y worddate.;
x='03Jan1960'd;
y=x;
put x / y; * the character ' / ' prints the value of y on the next line;
run;
The output is as follows:
2
January 3, 1960
Both the variables x and y represent the date 03Jan1960, but x is not formatted whereas y has a format worddate.
Hope this makes it clear.

3. SAS dates are stored as numeric values (to allow calculations such as INTCK and INTNX), the date is effectively just a format on the number. The SAS date system starts on 01JAN1960 (which has the numeric value 0) so the unformatted result of going forward 1 week with the beginning alignment is 2 (if you formatted this as date9, you would get 03JAN1960).
If you use Excel much, you might know that it does something similar - if you format a cell with a date in it as a number you'll get a cryptic integer. Zero in excel is 01JAN1900.
I use date functions quite a lot in SAS. They're good if you have datasets from different points in time and want to get data from two or more points to compare - such as comparing the data this period to the end of the previous year, INTNX (‘year’, , -1,'end'), or the equivalent period last year, INTNX('year',,-1,'sameday').
Having functions like these means that you can code macros with less parameters and more consistent results.