In this example, we created a new variable called YEARS_JOIN_C.
The YEARS_JOIN_C variable has a fourth parameter.
The fourth parameter was specified as 'cont', which tells SAS to use the 'continuous' alignment instead of the default alignment.
When specifying the 'continuous' alignment, the INTCK function counts the number of full years in the entire period.
Let's look at Mary as an example.
Mary's membership started on October 1, 2018 but ended before October 1, 2019.
The entire period lasted for less than a full year:
SAS returns the value (0), indicating Mary has joined the gym for less than a year.
Let's also look at the other two gym members.
John and Peter have in fact been gym members for over a full year.
The INTCK function returns the value (1) for both of them:
Important
Understanding when to specify the alignment is crucial when using the INTCK function.
Sometimes, the default alignment will return the correct results.
Let's look at another example.
Copy and run the code from the yellow box below:
The EMPLOYEE data set contains a list of five employees and the date of their hiring.
The company offers medical insurance for employees who have been with the company for at least a year.
Employees are considered to have been with the company for at least a year if they were with the company the previous calendar years.
Below are some examples of the tenure definition as of the year of 2019.
Now, we are going to compute the tenure for our five employees.
The calculation is done as of January 2, 2019 (beginning of the year).
The INTCK function without the 'continuous' alignment is used for the calculation:
data emp_tenure; set employee; tenure = intck('year', hiredate, '02JAN2019'd); run;
In this example, the interval is specified as 'year'.
The start date and end date are specified as the HIREDATE and the date of January 2, 2019, respectively:
The employee tenure is calculated as shown below:
Let's quickly verify the results by looking at employee ID1002.
ID1002 joined the company on September 18, 2018.
Based on the company's HR policy, ID1002 is considered to have already been with the company for a year as of 2019, since he/she was with the company the previous year (2018).
The tenure calculated is 1, which is correct!
Exercise
Copy and run the code from the yellow box below:
The SHOP data set contains three variables:
PRODUCT_ID
STOCK_DATE
QUANTITY_REM
The PRODUCT_ID is the unique ID of each product.
The STOCK_DATE is the date when the products were stocked and put on the shelf.
The QUANTITY_REM is the quantity that remained in stock as of February 1, 2019.
The shop owner wants to find out how many products have been on the shelf for three full months as of Feb 1, 2019.
Help the owner calculate the total number of products that are unsold after being in stock for over three months.