Your have data set has 4 records, but your want data sets have 5 records.
Are you sure for want2, the last one should be 5, not 6? If it is 6, I think this mostly works.
data want;
set have;
timestores = intck('weekday', date1, date2);
*if start on weekend, move to first weekday;
if weekday(date1) in (1,7) then date_start = intnx('weekday', date1, 1, 'b');
else date_start = date1;
format date_start yymmdd10.;
*second calculation;
timestores2 = intck('day', date_start, date2);
run;
@sasgorilla wrote:
You are right, sorry for not including code for clarity. Please see below.
data have;
input date1 :yymmdd10. date2 :yymmdd10.;
format date1 yymmdd10. date2 yymmdd10.;
datalines;
2024-11-02 2024-11-04
2024-11-04 2024-11-04
2024-11-05 2024-11-07
2024-11-07 2024-11-11
;
RUN;
data want1 /*don't count only 1st weekend if date1 on 1st weekend*/;
input date1 :yymmdd10. date2 :yymmdd10. timetores;
format date1 yymmdd10. date2 yymmdd10.;
datalines;
2024-11-02 2024-11-04 0
2024-11-04 2024-11-04 0
2024-11-05 2024-11-07 2
2024-11-07 2024-11-11 4
2024-11-09 2024-11-18 7
;
RUN;
data want2 /*never count weekend*/;
input date1 :yymmdd10. date2 :yymmdd10. timetores;
format date1 yymmdd10. date2 yymmdd10.;
datalines;
2024-11-02 2024-11-04 0
2024-11-04 2024-11-04 0
2024-11-05 2024-11-07 2
2024-11-07 2024-11-11 2
2024-11-09 2024-11-18 5
;
RUN;
... View more