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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 749 views
  • 0 likes
  • 3 in conversation