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!
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
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.
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.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.