I have an fcmp function with an array, but the IN operator doesn't seem to work. What am I doing wrong?
proc fcmp outlib=mylib.UserFuncLib.dateFuncs;
function previousWorkingDayDate(dateWeekday);
* Not a weekend and not a bank holiday;
dayBefore = intnx('Day',dateWeekday,-1);
* Array of bank holidays, needs to be kept updated;
array bankHolidays[9] / nosymbols
('03Jan2022'd '15Apr2022'd '18Apr2022'd '02May2022'd
'02Jun2022'd '03Jun2022'd '29Aug2022'd '26Dec2022'd
'27Dec2022'd );
do while ((dayBefore in bankHolidays) or weekday(dayBefore) < 2 or weekday(dayBefore) > 6);
dayBefore = intnx('Day',dateWeekday,-1);
end;
return(dayBefore);
endsub;
The code dayBefore in bankHolidays gives ERROR 79-322: Expecting a (.
Help! Thanks.
CodePudding user response:
I think this just is a case of a SAS syntax that isn't supported in FCMP. In fact, I think SAS knows this... when I change it slightly to include the parentheses, the error message is telling:
80 do while ((dayBefore in (bankHolidays) or weekday(dayBefore) < 2 or weekday(dayBefore) > 6));
ERROR: The array 'bankHolidays' cannot be an argument of the 'IN' operation.
From the FCMP Documentation, I think this is more explicitly stated:
The ARRAY statement that is used in PROC FCMP does not support all the features of the ARRAY statement in the DATA step. Here is a list of differences that apply only to PROC FCMP:
- All array references must have explicit subscript expressions.
You could solve this a few different ways; simplest is just to iterate over it (or even write another FCMP function that does that for you), or use a macro variable.
If you're really set on trying to do this, you might ask SAS directly (support @ sas.com) and see if they can give you a definitive answer on whether there is a direct way to do this.