All the major SAS string handling functions have a macro equivalent:
Especially when using %scan, one often has to use %sysfunc(countw()) to initialize a macro loop.
So I propose to create a macro equivalent of countw, namely %countw, similar in function to %scan with regards to delimiters and modifiers.
I don't often react to proposals with "but you can already do it like ... ", but in this case I'm wondering why having %countw would be better than %sysfunc(countw())? (Other than the fact that I mistype %sysfunc about 30% of the time).
I suppose it would highlight it in the documentation, when someone was browsing for macro functions. Are you thinking there might be an efficiency benefit to having a native macro function?
I haven't been around long enough to know the history. I assume %sysfunc() was added to the macro language at some point. Could it be that the functions you listed were around before there was %sysfunc, and now that they gave us %sysfunc, there isn't a need for SAS to develop more macro functions that are translations of data step functions?
(Other than the fact that I mistype %sysfunc about 30% of the time)
The proposed function would reduce complexity in typing and reading code. Given the fact that the macro facility is a pure text processor, having native string handling functions only seems natural. Especially when one thinks that %scan() is already there, and I rarely use scan() in a datastep without countw(), and %scan() without %sysfunc(countw()).
It's a bit of a slippery slope… there's a lot of data step functions that could be added to the macro language.
@Quentin is correct: the existing macro string handling was present before the addition of %sysfunc, and macro and data step were at least on the same playing field for capability. Then %sysfunc was added and there's been almost no new macro functions added since.
It is unwieldy, particularly when you embed %sysfunc within %sysfunc, but the power's there
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.