BookmarkSubscribeRSS Feed
Go210
Obsidian | Level 7

 

Hi All,

 

I am trying to think of a smart way to resolve this issue.

 

I have a list of dates in SAS format and I want to just put a flag to show its a holiday. However, if the day falls on a weekend (Saturday or Sunday) then I want flag = 1 for the Monday.

 

eg Christmas Day 25/12/2016 falls on a Sunday therefore I would the monday to be flagged as a holiday my output to be:

 

Date             Flag

24/12/2016      0

25/12/2016      1

26/12/2016      0

27/12/2016      1

28/12/2016      0

 

 

Also Easter Sunday is flagged, but I need to flag the previous Friday (Good Friday) and the following monday.

 

In 2018, Easter Sunday was on 1st of April.

 

eg. Easter

Date             Flag

29/03/2018      0

30/03/2018      1

31/03/2018      0

01/04/2018      1

02/04/2018      1

03/04/2018      0

 

 

 

Any help would be greatly appreciated.

 

 

data have;
set date_list;
flag=0

 

/*Christmas*/
if month(date) = 12 and day(date) = 25 then flag = 1;
if month(date) = 12 and day(date) = 25 and (Weekday(Date)=1 or Weekday(Date)=7) then do;

 

<some code>


end;

 

/*Easter Sunday*/

if date = holiday('easter',year(date)) then flag =1;

 

/*Need to Flag Previous Friday and Next Day After Easter (Monday)*/

 

 

 

run;

 

 

 

4 REPLIES 4
ChrisNZ
Tourmaline | Level 20

I think you are over complicating the problem. Something like this (untested) does what you want:

 

if put(DATE,date7.) =: '26DEC' and put(DATE,downame.)='Monday' then FLAG = 1;

if put(DATE,date7.) =: '27DEC' and put(DATE,downame.)='Monday' then FLAG = 1;

 

The code is also more legible.

SASKiwi
PROC Star

Why not check your holiday dates generically? This logic will work regardless of the holiday date specified.

 

data _null_;
  format holiday_date next_holiday_date date9.;
  holiday_date = '25Dec2016'd;
  if day(holiday_date) in (1,7) then next_holiday_date = intnx('WEEKDAY', holiday_date, 1);
run;
Go210
Obsidian | Level 7

Thanks Guys.

 

I have kept it simpler like you have suggested and it is working fine.

 

For Easter I just created a Good Friday & Easter Monday variable by -2 days for Good Friday from the Easter Date and +1 Day for Easter Monday.

 

I then just rejoined the dates back to the main dataset.

 

Cheers

Reeza
Super User

You can also use the Holiday Functions to return the US holidays, it seems like Good Friday may not be included though. 

http://documentation.sas.com/?cdcId=pgmmvacdc&cdcVersion=9.4&docsetId=lefunctionsref&docsetTarget=n0...

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

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
  • 4 replies
  • 2151 views
  • 0 likes
  • 4 in conversation