SAS (Base SAS)+
*=============================================================================;
* Calculate the difference between two dates using INTCK
*=============================================================================;
*-----------------------------------------------------------------------------;
* Create sample adverse event data with reference start dates
*-----------------------------------------------------------------------------;
data ae;
input usubjid $ rfstdtc :date9. aestdtc :date9. aeendtc :date9.;
format rfstdtc aestdtc aeendtc date9.;
datalines;
S001 01JAN2025 05JAN2025 12JAN2025
S001 01JAN2025 15FEB2025 20FEB2025
S002 10FEB2025 10FEB2025 10MAR2025
S002 10FEB2025 25MAR2025 30APR2025
S003 01MAR2025 15MAR2025 15MAR2025
;
run;
*-----------------------------------------------------------------------------;
* Derive study day, AE duration, and month interval
*-----------------------------------------------------------------------------;
data ae_derived;
set ae;
* Day count between two dates;
day_diff = intck('DAY', rfstdtc, aestdtc);
* Study day: add 1 when the event is on or after reference date;
if aestdtc >= rfstdtc then astdy = day_diff + 1;
else astdy = day_diff;
* Duration of adverse event in days;
ae_dur = intck('DAY', aestdtc, aeendtc) + 1;
* Month count between reference and AE start;
month_diff = intck('MONTH', rfstdtc, aestdtc);
* Year count between reference and AE start;
year_diff = intck('YEAR', rfstdtc, aestdtc);
run;
proc print data=ae_derived noobs;
run;- We create a small AE dataset with three subjects, each having a reference start date (rfstdtc), AE start date (aestdtc), and AE end date (aeendtc).
intck('DAY', rfstdtc, aestdtc)counts the number of day boundaries crossed between the two dates β this is a simple subtraction for days.- To derive study day (ASTDY), we add 1 when the event is on or after the reference date, because CDISC study day has no day zero.
- For events before the reference date, the day difference is already negative, so we leave it as is β day β1 is the day before reference start.
intck('DAY', aestdtc, aeendtc) + 1gives the duration of the AE in days; we add 1 because both the start and end day are counted.intck('MONTH', rfstdtc, aestdtc)counts how many first-of-month boundaries the interval crosses β it does not count partial months.intck('YEAR', rfstdtc, aestdtc)works the same way for year boundaries.- We run PROC PRINT and confirm that subject S002's first AE on the same day as reference start gives ASTDY = 1, not 0.