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 ;
BASUG is hosting free webinars Next up: Mike Sale presenting Data Warehousing with SAS April 10 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

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 ;
BASUG is hosting free webinars Next up: Mike Sale presenting Data Warehousing with SAS April 10 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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