You could add some error handling for such cases. Something like:
if weekday(date2) in (1,7) then
do;
/* here some error handling code */
end;
You could for example ensure that your time_stores variables become missing if date2 falls on a weekend and though is invalid. Or you could "fix" the data and shift it on to the next Monday.
data want;
set have;
format date1 date2 shift_date1 shift_date2 weekdatx.;
shift_date1=date1;
shift_date2=date2;
if weekday(shift_date2) in (1,7) then
do;
/* Option1: set shift_date2 to missing so derived variables become missing */
/* shift_date2=.; */
/* Option2: "fix" data by shifting date2 to Monday */
shift_date2=intnx('weekday17w',shift_date2,1);
end;
/* 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=shift_date2-shift_date1;
/* derived_timetores_1=intck('day',shift_date1,shift_date2); */
derived_timetores_2=intck('weekday17w',shift_date1,shift_date2);
run;
... View more