1

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.

CaptainFuzzyFace
  • 339
  • 1
  • 3
  • 11
  • Taking a look, but something important to understand about FCMP is that its language looks like Base SAS, feels like Base SAS, but it isn't actually Base SAS... so there are lots of weird edge cases that don't work the way you expect. – Joe Feb 23 '22 at 15:46
  • Thanks Joe. Yes, I've read that it's different, but I can't find a note on how this differs. I'm also fairly new to SAS so I don't have any preconceived notions. – CaptainFuzzyFace Feb 24 '22 at 11:08

1 Answers1

1

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.

Joe
  • 62,789
  • 6
  • 49
  • 67