BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
PaigeMiller
Diamond | Level 26

What does the second argument to the HOLIDAYNAME function do? The documentation is basically non-explanatory here. It says "N  specified the index". No further explanation about what the index does.

 

I have to say that usually, SAS documentation is excellent, but here it falls flat on its face.

--
Paige Miller
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Good morning Sir @PaigeMiller  Thank you for the excellent question. Here is my guess on reviewing the example in the documentation

 

data a;
   length Holiday $32;
   format date weekdatx17.;
   do year=2000 to 2010;
      date=mdy(11,11,year);
      ObsVetNov11=holidaycount(date);
      do index=1 to ObsVetNov11;
         Holiday=holidayname(date,index);
         output;
      end;
   end;
run;

Apparently the index refers to the same day i.e if holiday is being referred to more than one holidayname. The index number seems to provide that unique internal lookup identifier that fetches distinct holidaynames for the same date. As the program computes the hoildaycount, which is used in nested loop, my thought process invariably points to that understanding.

 

For example, British dominions have boxing day and the same has different names in different countries.

 

My 2 cents!

View solution in original post

6 REPLIES 6
novinosrin
Tourmaline | Level 20

Good morning Sir @PaigeMiller  Thank you for the excellent question. Here is my guess on reviewing the example in the documentation

 

data a;
   length Holiday $32;
   format date weekdatx17.;
   do year=2000 to 2010;
      date=mdy(11,11,year);
      ObsVetNov11=holidaycount(date);
      do index=1 to ObsVetNov11;
         Holiday=holidayname(date,index);
         output;
      end;
   end;
run;

Apparently the index refers to the same day i.e if holiday is being referred to more than one holidayname. The index number seems to provide that unique internal lookup identifier that fetches distinct holidaynames for the same date. As the program computes the hoildaycount, which is used in nested loop, my thought process invariably points to that understanding.

 

For example, British dominions have boxing day and the same has different names in different countries.

 

My 2 cents!

PaigeMiller
Diamond | Level 26

That's a very good explanation @novinosrin and probably correct, but it still leaves me unable to use this argument as I don't know what the meanings of index=1 and index=2 and index=3 are, and what all the possible results are from the HOLIDAYNAME function.

 

Again, a horrible failure of the documentation.

--
Paige Miller
novinosrin
Tourmaline | Level 20

Yes true and I agree. SAS Inc should have a LOOK-UP reference file. And considering, SAS a global company, the LOOK UP reference file for holidays should account for all countries where SAS operates. 

PaigeMiller
Diamond | Level 26

Perhaps I should ask a broader question ... I want to identify holidays, not only this year but perhaps several years in the future or past. What is a good method to do this? With HOLIDAYNAME() I can identify not only THANKSGIVING and PRESIDENTS day in the US, but I can also ignore other holidays not relevant to my project such as HALLOWEEN.

--
Paige Miller
ballardw
Super User

@PaigeMiller wrote:

Perhaps I should ask a broader question ... I want to identify holidays, not only this year but perhaps several years in the future or past. What is a good method to do this? With HOLIDAYNAME() I can identify not only THANKSGIVING and PRESIDENTS day in the US, but I can also ignore other holidays not relevant to my project such as HALLOWEEN.


Maybe the HOLIDAYNX function would help. This examples gets the next 10 Thanksgiving dates relative the to first of October in 2019.

data example;
   do i=1 to 10;
      thxdate= holidaynx('Thanksgiving','01OCT2019'd,i);
      output;
   end;
   format thxdate date9.;
run; 

I picked Thanksgiving since the date move a bit.

unison
Lapis Lazuli | Level 10

It looks like the index allows you to discern between different holidays that have fallen on the same date.

In @novinosrin's example, Veteran's day is observed in three different holiday schemes: Julian/calendar, US Gov., Postal (USPS). The index is somewhat unpredictable for holidays that depend on whether or not the true calendar day falls on a weekend (US Government holidays will always fall on a weekday -- fantastic if you work in the Public sector :)). See here:

 

data test;
   length holiday $32;
   format date weekdatx17.;
   do date='01jan2017'd to '31dec2019'd;
      cnt=holidaycount(date);
      do index=1 to cnt;
         holiday=holidayname(date,index);
         if holiday in ('VETERANS' 'VETERANSUSG') then output;
      end;
   end;
run;

 

If you want only specific holiday dates for a given time range, you might scan across the years of interest and then pull out the holidays you want by name.

 

-unison

-unison

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 6 replies
  • 933 views
  • 1 like
  • 4 in conversation