Desktop productivity for business analysts and programmers

Holiday Function in Advanced Filter Builder

Reply
New Contributor
Posts: 2

Holiday Function in Advanced Filter Builder

Hi! I am trying to build a function that returns the prior weekday and considers holidays. I have done this in the advanced filter builder by using a case statement that says if the prior weekday is a holiday, return two weekdays prior, otherwise return the prior weekday. My coding does not error, but my project spins until ultimately freezing up. Can you please tell me if this option is not a viable solution and/or what is? I'm hoping to do this using advanced filter builder rather than writing a program or proc statement as I am fairly new to coding in SAS EG.

 

CASE

WHEN INTNX('weekday', today(),-1) = holiday('newyear',year(today())) THEN t1.PriceDate = INTNX('weekday', today(),-2)

WHEN INTNX('weekday', today(),-1) = holiday('mlk',year(today())) THEN t1.PriceDate = INTNX('weekday', today(),-2)

WHEN INTNX('weekday', today(),-1) = holiday('uspresidents',year(today())) THEN t1.PriceDate = INTNX('weekday', today(),-2)

WHEN INTNX('weekday', today(),-1) = holiday('memorial',year(today())) THEN t1.PriceDate = INTNX('weekday', today(),-2)

WHEN INTNX('weekday', today(),-1) = holiday('usindependence',year(today())) THEN t1.PriceDate = INTNX('weekday', today(),-2)

WHEN INTNX('weekday', today(),-1) = holiday('labor',year(today())) THEN t1.PriceDate = INTNX('weekday', today(),-2)

WHEN INTNX('weekday', today(),-1) = holiday('thanksgiving',year(today())) THEN t1.PriceDate = INTNX('weekday', today(),-2)

WHEN INTNX('weekday', today(),-1) = holiday('christmas',year(today())) THEN t1.PriceDate = INTNX('weekday', today(),-2)

ELSE t1.PriceDate = INTNX('weekday', today(),-1)

END

 

Thanks!

PROC Star
Posts: 8,115

Re: Holiday Function in Advanced Filter Builder

Posted in reply to mnvandyke06

You didn't provide enough info/code for anyone to know what you are really trying to do. I'd presume that you want PriceDate to be dependent on a date in your dataset but, currently, you are only tying it to today's date.

 

Regardless, your case statement isn't formatted properly. Here is an example of your code formatted properly:

data test;
  input dates date9.;
  format dates date9.;
  cards;
22DEC2017
23DEC2017
24DEC2017
25DEC2017
26DEC2017
27DEC2017
28DEC2017
29DEC2017
30DEC2017
31DEC2017
1JAN2018
;

proc sql;
  create table want as
    select *,
           CASE
             WHEN INTNX('weekday', today(),-1) = holiday('newyear',year(today())) THEN INTNX('weekday', today(),-2)
             WHEN INTNX('weekday', today(),-1) = holiday('mlk',year(today())) THEN INTNX('weekday', today(),-2)
             WHEN INTNX('weekday', today(),-1) = holiday('uspresidents',year(today())) THEN INTNX('weekday', today(),-2)
             WHEN INTNX('weekday', today(),-1) = holiday('memorial',year(today())) THEN INTNX('weekday', today(),-2)
             WHEN INTNX('weekday', today(),-1) = holiday('usindependence',year(today())) THEN INTNX('weekday', today(),-2)
             WHEN INTNX('weekday', today(),-1) = holiday('labor',year(today())) THEN INTNX('weekday', today(),-2)
             WHEN INTNX('weekday', today(),-1) = holiday('thanksgiving',year(today())) THEN INTNX('weekday', today(),-2)
             WHEN INTNX('weekday', today(),-1) = holiday('christmas',year(today())) THEN INTNX('weekday', today(),-2)
             ELSE INTNX('weekday', today(),-1)
           END as PriceDate format=date9.
      from test
  ;
quit;

Art, CEO, AnalystFinder.com

 

Respected Advisor
Posts: 4,569

Re: Holiday Function in Advanced Filter Builder

Posted in reply to mnvandyke06

@mnvandyke06

On top of what @art297 wrote: The holiday() function is based on US holidays only. If you need anything else then you might also consider to create a custom interval. A variation of the docu "Example 3: Using Custom Intervals with the INTCK Function" should get you there.

 

http://documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=p0syn64amroombn14vrdzksh459w.htm&...

Ask a Question
Discussion stats
  • 2 replies
  • 183 views
  • 0 likes
  • 3 in conversation