BookmarkSubscribeRSS Feed
wtien196838
Quartz | Level 8

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

4 REPLIES 4
ballardw
Super User

Are your dates SAS date valued variables or character variables?

wtien196838
Quartz | Level 8

It is character variable on date field.

mkeintz
PROC Star

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.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
wtien196838
Quartz | Level 8

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

 

Thanks for your effort.

 

WT196838

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
  • 1323 views
  • 0 likes
  • 3 in conversation