@sasgorilla wrote:
Thanks, Patrick! This appears to have worked except there is one particular observation that is (-) for both values, (-2) for want1 and (-1) for want2. This is the only negative value out of a couple thousand observations.
For this observation, Date1=04/09/2022 and Date 2=04/09/2022;
Any ideas on how to troubleshoot to figure out what's causing this?
That's because your Date2 is on a Sunday which is obviously not a working day and though based on your initial definition shouldn't be possible.
If you have to cater for such cases then you need to provide amended sample data that covers such cases, shows the desired result and explains the logic.
/* timetores_1: don't count only 1st weekend if date1 on 1st weekend */
/* timetores_1: never count weekend */
data have;
input date1 :yymmdd10. date2 :yymmdd10. timetores_1 timetores_2;
format date1 yymmdd10. date2 yymmdd10.;
datalines;
2024-11-02 2024-11-04 0 0
2024-11-04 2024-11-04 0 0
2024-11-05 2024-11-07 2 2
2024-11-07 2024-11-11 4 2
2024-11-09 2024-11-18 7 5
2022-09-04 2022-09-04 0 0
;
run;
data want;
set have;
format date1 date2 shift_date1 weekdatx.;
shift_date1=date1;
/* if shift_date1 a Saturday or Sunday shift it to Monday */
if weekday(shift_date1) in (1,7) then shift_date1=intnx('weekday17w',shift_date1,1);
derived_timetores_1=date2-shift_date1;
/* derived_timetores_1=intck('day',shift_date1,date2); */
derived_timetores_2=intck('weekday17w',shift_date1,date2);
run;
proc print data=want;
run;
... View more