INTCK function in SAS difference between two dates and timestamp

INTCK() Function in SAS is used to find Difference between two dates in Timestamp. INTCK() Function in SAS calculates difference between two dates , INTCK() function also finds difference between two datetime and timestamp. Number of working days between two dates in SAS is also accomplished using INTCK function Let’s see an Example of each

  • INTCK() Function in SAS – difference between two dates in days, weeks, months & year
  • INTCK() Function in SAS – difference between two datetime in seconds, minutes, & hours
  • Number of Week days in SAS –INTCK() Function
  • Number of Working days between two dates – INTCK() Function

Syntax INTCK in SAS:

INTCK(‘Interval’, start_date, end_date)
  • Interval – can be in minutes, seconds, hours,weeks, days, months,quarter and year
  • Start_date and end_date are between two dates which we will be finding interval

So we will be using EMP_DET Table in our example

INTCK function in SAS difference between dates and timestamp 1

 

 

Difference Between two dates using INTCK function in SAS:

difference between two dates in days, weeks, months & year in SAS using INTCK() Function is accomplished by taking ‘day’, ‘week’, ‘month’ and ‘year’ as argument respectively


data emp_det1; 
set emp_det; 
days_diff = intck('day',DOJ,curr_date); 
week_diff = intck('week',DOJ,curr_date); 
month_diff = intck('months',DOJ,curr_date); 
year_diff = intck('year',DOJ,curr_date); 
run; 

So the resultant dataframe will be

INTCK function in SAS difference between dates and timestamp 2

 

 

Number or working days between two dates in SAS:

Number of working days between two dates in SAS is accomplished using INTCK function with ‘weekdays’ as argument as shown below.

/* number of working days between two dates */ 

data emp_det1; 
set emp_det; 
weekdays = intck('weekdays',DOJ,curr_date); 
run; 

So the resultant dataframe will be

INTCK function in SAS difference between dates and timestamp 3

 

 

Difference Between two timestamp using INTCK function in SAS:

Difference between two timestamps in hours, minutes & seconds in SAS using INTCK() Function is accomplished by taking ‘hour’, ‘minute’ and ‘second’ as argument respectively


data emp_det1; 
set emp_det; 
hours_diff = intck('hour',last_login,curr_datetime); 
minutes_diff = intck('minute',last_login,curr_datetime); 
second_diff = intck('second',last_login,curr_datetime); 
run;

So the resultant dataframe will be

INTCK function in SAS difference between dates and timestamp 4

 

                                                                                               

Author

  • Sridhar Venkatachalam

    With close to 10 years on Experience in data science and machine learning Have extensively worked on programming languages like R, Python (Pandas), SAS, Pyspark.

    View all posts