BookmarkSubscribeRSS Feed
CADSP
Calcite | Level 5

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

 

 

 

5 REPLIES 5
SASKiwi
PROC Star

This blog should help. The SAS function discussed INTNX works in SQL. 

CADSP
Calcite | Level 5

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).

 

 

SASKiwi
PROC Star

Please post your input data, your required output data and the code you have tried.

CADSP
Calcite | Level 5

Input data:

CADSP_0-1591962826916.png

REQUIRED OUTPUT:

CADSP_1-1591963373226.png

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;
ChrisHemedinger
Community Manager

This blog about emulating the NETWORKDAYS function from Excel might also help.

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Creating Custom Steps in SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 2123 views
  • 1 like
  • 3 in conversation