This is what Werner's example does (thank you very much !). I didn't know about the vectorization tool, and it seems to do the trick. I am just a bit puzzled why I can't apply it with k and y being global variables rather than function parameters.
This is because of the if statement. Its argument has to be a scalar (0 means false, any other number is interpreted as true). If you use global vectors in your comparison, the result is a vector consisting of 0's and/or 1's. Obvisously Mathcad can't decide if it should interprete such a vector as true or false - its no scalar and so the error is thrown. This applies to the programming if statement and to the if function likewise.
With my approach the call of the function g(x,k,y) ist vectorized, Mathcad loops through the involved vectors, feeds the called function g() with the single elements and collects the various results in a vector. So the function g() never sees a vector but is just fed with scalars and so the if construct works.
I generally find it the preferred approach that a function should be self contained - that all thats needed for the calculation should be either hard coded or provided via function argument. Its less failure prone and more versatile that way.
But if you insist on defining g(x) with just one argument and using global y and k you can do that if you replace the if statement by a sum using boolean expressions. We use here that a false statement yields zero and a true one yields 1. See g1() and g2().
And of course you are free to program the looping through your vectors yourself and use either the if function or the if statement. See g3() and g4().