BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
lsandell
Obsidian | Level 7

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? 

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

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 ;
The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in March 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.

View solution in original post

4 REPLIES 4
awesome_opossum
Obsidian | Level 7

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? 

Quentin
Super User

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 ;
The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in March 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
ballardw
Super User

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.

 

lsandell
Obsidian | Level 7
Thank you! I can see the utility of this function. I appreciate your quick response and help on this!

sas-innovate-wordmark-2025-midnight.png

Register Today!

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.


Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 868 views
  • 4 likes
  • 4 in conversation