Hi guys,
I have a table on a server with Holiday data, I would like to get the working days before and after the holiday dates.
The later ones I manage to do with 'case weekdate' for some cases, but my difficulty is on holidays. How can I do this within PROC SQL?
For exemple:
Holiday DscHoliday UPHoliday LWHoliday
24-02-20 Carnaval 26-02-20 21-02-20
25-02-20 Carnaval 26-02-20 21-02-20
This blog should help. The SAS function discussed INTNX works in SQL.
I tried to use this function, but I couldn't do what I wanted at the end, when I have two holidays in a row I would have to show me the same previous business day, but she can only show me the previous day of the line in question.
(Maybe I can do it, but I'm still new to SAS).
Please post your input data, your required output data and the code you have tried.
Input data:
REQUIRED OUTPUT:
Note: 31/12/2019 and 01/01/2021 are public holidays(Feriado)
My code:
proc sql;
create table work.holidays as
select Cod, DescFeriado, DtFeriado
case when weekday(datepart(DtFeriado)) in (2,3,4,5) then
datepart(DtFeriado)+1
when weekday(datepart(DtFeriado))=6 then datepart(DtFeriado)+3
when weekday(datepart(DtFeriado))=7 then datepart(DtFeriado)+2
when weekday(datepart(DtFeriado))=1 then datepart(DtFeriado)+1
end as UPFeriado FORMAT=date9.,
case when weekday(datepart(DtFeriado)) in (3,4,5,6,7) then
datepart(DtFeriado)-1
when weekday(datepart(DtFeriado))=2 then datepart(DtFeriado)-3
when weekday(datepart(DtFeriado))=1 then datepart(DtFeriado)-2
end as LowerFeriado FORMAT=date9.,
from TableFeriados
where DtFeriao>='01jan2020:0:0:0'dt;
This blog about emulating the NETWORKDAYS function from Excel might also help.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.