/***************************************************************************************************************** SAS file name: Dates.sas File location: _________________________________________________________________________________________________________________ Purpose: Demonstrate the basics of working with dates in SAS and present the INTNX and INTCK functions Author: Peter Clemmensen Creation Date: 25/07/2017 This program supports the blog post "Date Basics in SAS" on SASnrd.com *****************************************************************************************************************/ /* Dates from 30dec1959 to 03jan1960, with and without format */ data dates; do dt = -2 to 2; dt_formatted = dt; output; end; format dt_Formatted date9.; run; proc print data=dates; run; /* INTNX Examples */ /* "I want to know the date exactly 21 days from December 24th 2017" */ data _null_; date=intnx('day', '24dec2017'd, 21); format date date9.; put date; run; /* "I want to know the date of the first day of the month 3 months from today" */ data _null_; date=intnx('month', today(), 3, 'b'); format date date9.; put date; run; /* "I want to know the date of the first Thursday of next month" */ data _null_; date=intnx('week.5', intnx('month',today(),0,'e'), 1, 'b'); format date date9.; put date; run; /* INTCK Examples */ /* I want the number of days until Christmas eve */ data _null_; days=intck('day',today(),'24dec2017'd); put days; run; /* I want the number of days between next Tuesday and New Years Eve */ data _null_; days=intck('day', intnx('week.5', today(), 1, 'b'), '31dec2017'd); put days; run;