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
PROC Star

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 ;
Check out the Boston Area SAS Users Group (BASUG) video archives: https://www.basug.org/videos.

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
PROC Star

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 ;
Check out the Boston Area SAS Users Group (BASUG) video archives: https://www.basug.org/videos.
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

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

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