![]() intck ('YEAR.3', date1, date2) - It checks number of times first of March appears as YEAR.3 refers to the period starting from 1st of March to end of February next year.The variable diff returns 1 as it includes only 01JAN 2016. intck ('YEAR', date1, date2) - It checks number of times first of January appears as first of january is set as a starting point by default.It would return 1 for the above mentioned dates. For example, ' YEAR2' tells SAS the interval is of 2 years. Similarly, we can use the custom intervals in YEAR, QUARTER and other periods. QUARTERS is equal to interval of 3 months. It is equal to the number of months divided by 4. The MONTH4 interval implies interval is of 4 months. No_of_4months = intck (' MONTH4', date1, date2) Suppose you are asked to calculate the number of 4 months interval between two dates. No_of_days = intck (' DAY', date1, date2) No_of_weeks = intck (' WEEK', date1, date2) No_of_months = intck (' MONTH', date1, date2) No_of_quarters = intck (' QUARTER', date1, date2) No_of_semiyears = intck (' SEMIYEAR', date1, date2) No_of_years = intck (' YEAR', date1, date2) The examples of these intervals are displayed below. Like calculation of years, we can use other intervals such as semiyear, quarter, month, week, day. No_of_years = intck ( 'YR', date1, date2) No_of_years = intck ( 'YEARS', date1, date2) The FORMAT statement is used to display datevalues in date format when we print our results. Since 01JAN2015 is a starting date, it is specified in the INTCK function before 01JAN2017. The 'YEAR' keyword tells SAS to calculate the number of intervals between dates in terms of year. No_of_years = intck ('YEAR', date1, date2) In this case, two dates are 01JAN2015 and 01JAN2017. 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.Calculate the number of years between two dates. 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. Notice the difference between this table and the previous table. Months_diff = intck(' months', start_date, end_date, ' c') ![]() Weeks_diff = intck(' weeks', start_date, end_date, ' c') ![]() ![]() Note that we can use the ‘ c‘ argument in the INTCK function to only calculate the difference in complete days, weeks, and months: /*create new dataset*/ĭays_diff = intck(' day', start_date, end_date, ' c') The three new variables show the difference between start_date and end_date in days, weeks, and months. Months_diff = intck(' months', start_date, end_date) Weeks_diff = intck(' weeks', start_date, end_date) We can use the following code to calculate the difference between the values in the start_date and end_date variables in days, weeks, and months: /*create new dataset*/ĭays_diff = intck(' day', start_date, end_date) Suppose we have the following dataset in SAS that contains two date variables: /*create dataset*/ Example : Calculate Difference Between Dates in SAS The following example shows how to use this function in practice. method: Whether to count complete intervals (‘D’ = No (Default), ‘C’ = Yes).interval: Interval to calculate (day, week, month, year, etc.).INTCK(interval, start date, end data, method) This function uses the following basic syntax: You can use the INTCK function in SAS to quickly calculate the difference between two dates in SAS. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |