The logic of your code is right, just need to move forward one step: You are trying to using a function-style macro on a normal variable in data step, which is the root of problem, what you really need is a function, not a macro.
%let current_date = %sysfunc(today(),yymmddn8.);
%let holiday_list = 08DEC2023 25DEC2023;
/* Function to check if a date is in the holiday list */
proc fcmp outlib=work.funcs.date;
function is_holiday(date,holiday_list$);
holiday=0;
do i=1 to countw(holiday_list);
if date=input(scan(holiday_list, i), date9.) then do;
holiday=1;
leave;
end;
end;
return(holiday);
endfunc;
run;
option cmplib=work.funcs;
/* Calculate the previous working day and adjust for holidays */
data _null_;
/* Convert the current date to SAS date format */
current_date_sas = input("¤t_date.", yymmdd8.);
/* Initialize variables */
previous_workday = current_date_sas;
i = 1;
/* Subtract days until a working day (Mon to Fri) is found */
do while (weekday(intnx('day', previous_workday, -i)) in (1, 7) or is_holiday(intnx('day', previous_workday, -i),"&holiday_list."));
i = i + 1;
end;
/* Calculate the previous working day considering holidays */
previous_workday = intnx('day', previous_workday, -i);
/* Check if the result is a holiday and adjust further */
if is_holiday(previous_workday,"&holiday_list.") then
previous_workday = intnx('day', previous_workday, -2);
/* Format the result as a date and store it in a macro variable */
call symput('previous_workday', put(previous_workday, date9.));
run;
/* Display the result in the log */
%put Previous working day is &previous_workday.;
And surely you can use intnx('workday',...) to simplify your code.
... View more