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
Are your dates SAS date valued variables or character variables?
It is character variable on date field.
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.
Thanks mkeintz. Your suggestion directs me to get the solution of my problem.
Thanks for your effort.
WT196838
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.
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.