Published on :
Date Functions CREATION_INTERNE

Calculate the difference in years with INTCK

This code is also available in: Deutsch English Español Français
The program uses a DATA _NULL_ step to perform date calculations without creating a dataset. The INTCK function is used to determine the number of 'year' intervals between specified dates. The results are then displayed in the SAS© log. The first calculation ('twoday') shows that INTCK('year', ...) only counts complete year transitions, while the second ('twoyr') shows a wider interval covering two years.
Data Analysis

Type : CREATION_INTERNE


The dates used for the calculation are directly hardcoded in the SAS code ('31dec2008'd, '01jan2009'd, '01jan2008'd, '31dec2009'd).

1 Code Block
DATA STEP
Explanation :
This DATA _NULL_ block uses the INTCK function to calculate the difference in 'year' between different date pairs. 'twoday' calculates the year interval between December 31, 2008, and January 1, 2009 (resulting in 0 because no full year has passed, only a calendar year change), while 'twoyr' calculates the interval between January 1, 2008, and December 31, 2009 (resulting in 1 because one full year, 2008, has passed). The results are then written to the SAS log using the PUT statement.
Copied!
1DATA _null_;
2 twoday = intck('year','31dec2008'd,'01jan2009'd);
3 twoyr = intck('year','01jan2008'd,'31dec2009'd);
4 put twoday= twoyr=;
5 RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.