I have a counter in my code that is as follows: %let counter = %sysfunc(countw(&&CLMNS&j.)); However this does not work properly for some macro variables. For variable_1, which contains the values Parent_Name, Name the counter returns as 3 (should be 2). For variable_2, which contains Alt_Parent_Name, Alt_Name the counter correctly returns a value of 2.
If I add a pair of parentheses, so it now is: %let counter = %sysfunc(countw((&&CLMNS&j.)));, it now correctly outputs a value of 2 for both variable_1 and variable_2.
I have read through the help cards to no avail and would like to figure out why this occurs and what the extra parentheses do. I am mostly confused by the inconsistency of the result in the first instance.
Perhaps this helps:
SAS will break it down in the following order:
%let counter = %sysfunc(countw(&&CLMNS&j.));&&) resolves to one ampersand (&) and the scanner continues.&j.in the global symbol table. E.g. to1.&CLMNS1in the global symbol table. E.g. tovariable_1(which would have to be resolved with another ampersand) or justParent_Name, Name.%let counter = %sysfunc(countw(Parent_Name, Name));Now you can perhaps see what is going wrong. When the compiler continues, it will understand
Nameas the optional argument<character(s)>incountw.What you want is instead to mask the output of
&&CLMNS&j.for the macro processor. I.e. use%NRSTR:Expected global symbol table:
These resources might be relevant for you: