How can the INTCK function be used in SAS and what are some examples of its usage? 2

How can the INTCK function be used in SAS and what are some examples of its usage?

The INTCK function is a useful tool in SAS that allows users to calculate the difference between two dates or times in a specified unit of measurement. This function can be used in various scenarios, such as calculating the age of a person, the length of a project, or the number of days between two events. It takes two parameters, the starting date/time and the ending date/time, and returns the number of intervals between them. The intervals can be specified in units such as days, weeks, months, or years. For example, the INTCK function can be used to determine the number of months between a person’s birth date and current date. It can also be used to calculate the duration of a project in weeks. Overall, the INTCK function is a powerful tool for time and date calculations in SAS.

Use INTCK Function in SAS (With Examples)


You can use the INTCK function in SAS to quickly calculate the difference between two dates in SAS.

This function uses the following basic syntax:

INTCK(interval, start date, end data, method)

where:

  • interval: Interval to calculate (day, week, month, quarter, year, etc.)
  • start date: The start date
  • end date: The end date
  • method: Count intervals using a discrete or continuous method

The following example shows how to use this function in practice.

Example: Using INTCK Function to Calculate Difference Between Dates in SAS

Suppose we have the following dataset in SAS that contains two date variables:

/*create dataset*/
data original_data;
    format start_date end_date date9.;
    input start_date :date9. end_date :date9.;
    datalines;
01JAN2022 09JAN2022
01FEB2022 22FEB2022 
14MAR2022 04APR2022
01MAY2022 14AUG2023
06AUG2022 10NOV2024
;
run;

/*view dataset*/
proc printdata=original_data;

We can use the following code to calculate the difference between the values in the start_date and end_date variables in days, weeks, months, quarters and years:

/*create new dataset*/
data new_data;
    set original_data;
    days_diff = intck('day', start_date, end_date);
    weeks_diff = intck('weeks', start_date, end_date);
    months_diff = intck('months', start_date, end_date);
    qtr_diff = intck('qtr', start_date, end_date);
    years_diff = intck('years', start_date, end_date);
run;

/*view new dataset*/
proc printdata=new_data;

 

INTCK function in SAS

The five new variables show the difference between start_date and end_date in days, weeks, months, quarters, and years.

Note that we can use the ‘c‘ argument in the INTCK function to only calculate the difference in complete days, weeks, months, quarters and years:

/*create new dataset*/
data new_data;
    set original_data;
    days_diff = intck('day', start_date, end_date, 'c');
    weeks_diff = intck('weeks', start_date, end_date, 'c');
    months_diff = intck('months', start_date, end_date, 'c');
    qtr_diff = intck('qtr', start_date, end_date, 'c');
    years_diff = intck('years', start_date, end_date, 'c');
run;

/*view new dataset*/
proc printdata=new_data;

Notice the difference between this table and the previous table.

In this table, the difference in weeks between Jan 1st and Jan 9th is calculated as 1 since only one whole week can fit between these dates.

However, in the previous table the difference in weeks was calculated as 2 since there were two partial weeks that fit between these two dates.

The following tutorials explain how to perform other common tasks in SAS:

Cite this article

stats writer (2024). How can the INTCK function be used in SAS and what are some examples of its usage?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-the-intck-function-be-used-in-sas-and-what-are-some-examples-of-its-usage/

stats writer. "How can the INTCK function be used in SAS and what are some examples of its usage?." PSYCHOLOGICAL SCALES, 23 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-the-intck-function-be-used-in-sas-and-what-are-some-examples-of-its-usage/.

stats writer. "How can the INTCK function be used in SAS and what are some examples of its usage?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-the-intck-function-be-used-in-sas-and-what-are-some-examples-of-its-usage/.

stats writer (2024) 'How can the INTCK function be used in SAS and what are some examples of its usage?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-the-intck-function-be-used-in-sas-and-what-are-some-examples-of-its-usage/.

[1] stats writer, "How can the INTCK function be used in SAS and what are some examples of its usage?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.

stats writer. How can the INTCK function be used in SAS and what are some examples of its usage?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.

Download Post (.PDF)
Slide Up
x
PDF
Scroll to Top