DATA Step, Macro, Functions and more

How to insert a Holiday value into week period that contains holiday ?

Reply
Contributor
Posts: 59

How to insert a Holiday value into week period that contains holiday ?

[ Edited ]

Dear SAS User community:

I have two datasets: one is Holiday and another is detail data with week period.
Example: Holiday dataset (two vars which contain Holiday date in a year of 2017):

Holiday          Holiday_DESC
...
04-JUL-17     Independent Day
04-SEP-17    Labor Day
....

Detail dataset (various vars that contain start-week and end-week)
* comment: start-week starts at Sunday

........ start_week end_week
....... 02-JUL-17 08-JUL-17
....... 09-JUL-17 15-JUL-17
........
........ 03-SEP-17 09-SEP-17

MY question is:

How to write sas codes to insert one var with 'HOL' value into week period that contains Holiday
and other week periods still blank ?

I want the result:

(vars) start_week   end_week      Holiday (new var)
.......    02-JUL-17  08-JUL-17       'HOL'
.......    09-JUL-17  15-JUL-17
........
........   03-SEP-17  09-SEP-17      'HOL'

Thanks for your instruction.

Regards,

WT196838

Super User
Posts: 13,073

Re: How to insert a Holiday value into week period that contains holiday ?

Posted in reply to wtien196838

Are your dates SAS date valued variables or character variables?

Contributor
Posts: 59

Re: How to insert a Holiday value into week period that contains holiday ?

It is character variable on date field.

Trusted Advisor
Posts: 1,288

Re: How to insert a Holiday value into week period that contains holiday ?

Posted in reply to wtien196838

Assuming your dates are true SAS date values, and that both datasets are sorted chronologically, you can pre-read the HOLIDAY dataset and generate corresponding START_DATE values.  Then merge with the WEEKS dataset:

 

data need / view=need;
  set holiday;
  start_date=intnx('week',holiday,0,'beg');
run;

data want;
  merge weeks need;
  by start_date;
run;

 

Note this assume all weeks begin on Sunday.

Contributor
Posts: 59

Re: How to insert a Holiday value into week period that contains holiday ?

Thanks mkeintz. Your suggestion directs me to get the solution of my problem.

 

Thanks for your effort.

 

WT196838

Ask a Question
Discussion stats
  • 4 replies
  • 116 views
  • 0 likes
  • 3 in conversation