无法使用 IN 在 fcmp 函数中搜索数组

Unable to use IN to search an array in a fcmp function

我有一个带数组的 fcmp 函数,但 IN 运算符似乎不起作用。我做错了什么?

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;

代码 dayBefore in bankHolidays 给出 ERROR 79-322: Expecting a (.

求助!谢谢

我认为这只是 FCMP 不支持的 SAS 语法的一个例子。事实上,我认为 SAS 知道这一点......当我稍微改变它以包含括号时,错误消息告诉:

  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.

FCMP Documentation来看,我觉得这个说的比较明确:

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.

您可以通过几种不同的方式解决这个问题;最简单的就是迭代它(或者甚至编写另一个 FCMP 函数来为您完成),或者使用宏变量。

如果您真的打算尝试这样做,您可以直接询问 SAS(支持 @ sas.com),看看他们是否可以就是否有直接的方法给您一个明确的答案这个。