Calculate Excess Between Two Dates in SAS


You’ll significance the INTCK serve as in SAS to briefly calculate the excess between two dates in SAS.

This serve as makes use of refer to unadorned syntax:

INTCK(break, get started day, finish information, mode)

the place:

  • break: Intermission to calculate (while, life, while, time, and so forth.)
  • get started day: The beginning day
  • finish day: The tip day
  • mode: Whether or not to depend whole durations (‘D’ = Negative (Default), ‘C’ = Sure)

Refer to instance presentations learn how to significance this serve as in follow.

Instance : Calculate Excess Between Dates in SAS

Assume we’ve refer to dataset in SAS that accommodates two day variables:

/*assemble dataset*/
information original_data;
    layout start_date end_date date9.;
    enter start_date :date9. end_date :date9.;
    datalines;
01JAN2022 09JAN2022
01FEB2022 22FEB2022 
14MAR2022 04APR2022
01MAY2022 14AUG2022
;
run;

/*view dataset*/
proc print information=original_data;

We will significance refer to code to calculate the excess between the values within the start_date and end_date variables in days, weeks, and months:

/*assemble untouched dataset*/
information new_data;
    prepared original_data;
    days_diff = intck('while', start_date, end_date);
    weeks_diff = intck('weeks', start_date, end_date);
    months_diff = intck('months', start_date, end_date);
run;

/*view untouched dataset*/
proc print information=new_data;

The 3 untouched variables display the excess between start_date and end_date in days, weeks, and months.

Notice that we will be able to significance the ‘c‘ argument within the INTCK serve as to simply calculate the excess in whole days, weeks, and months:

/*assemble untouched dataset*/
information new_data;
    prepared original_data;
    days_diff = intck('while', start_date, end_date, 'c');
    weeks_diff = intck('weeks', start_date, end_date, 'c');
    months_diff = intck('months', start_date, end_date, 'c');
run;

/*view untouched dataset*/
proc print information=new_data;

Understand the excess between this desk and the former desk.

On this desk, the excess in weeks between Jan 1st and Jan ninth is calculated as 1 since just one entire life can are compatible between those dates.

On the other hand, within the earlier desk the excess in weeks used to be calculated as 2 since there have been two favor weeks that are compatible between those two dates.

Supplementary Assets

Refer to tutorials give an explanation for learn how to carry out alternative ordinary duties in SAS:

Normalize Information in SAS
Exchange Characters in a Yarn in SAS
Exchange Lacking Values with 0 in SAS
Take away Duplicates in SAS

Leave a Comment