I would like to create an indicator/dummy variable to say whether or not the date (in this case, date of surgery) was on a US federal holiday. I have a date column and thousands of observations spanning multiple years of surgeries.
I could do multiple do loops for each year and use the holiday() function within that year for each holiday (if date of surgery is equal to '4th of July' or "thanksgiving' then holiday_dummy=1, for example) , but I'm wondering if there's a more efficient way to accomplish this?
There is a HolidayName() function, which returns blank if the date is not a holiday.
data _null_ ;
do date='01Jan2023'd to '31Dec2023'd ;
Holiday=HolidayName(date) ;
put date= Holiday= ;
end ;
format date date9. ;
run ;
Sorry to say, I don't have an answer for you. It's an interesting question analytically, but how could you possibly control for the fact that different holidays mean different things to different people?
There is a HolidayName() function, which returns blank if the date is not a holiday.
data _null_ ;
do date='01Jan2023'd to '31Dec2023'd ;
Holiday=HolidayName(date) ;
put date= Holiday= ;
end ;
format date date9. ;
run ;
Perhaps the Holidaycount function. It returns the number of holidays defined for a given date. Restricted to a single locale
data example; do date= '01Jan2023'd to '31DEC2023'd; dummy = (holidaycount(date,'English_UnitedStates') > 0); output; end; format date date9.; run;
May need to fine tune a bit for your specific use as this does indicate "defined' and "observed" for the holidays like Christmas, Veteran's Day and the 4th that move day of the week. Veteran's day may have two occurrences on the same day because there are two Federal rules for the holiday depending on whether you are US Postal office or other as the USPS usually works on Saturday and other agencies don't.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.