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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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