Become your own macro processor to see what the problem is. Replace the macro variable reference in your code with its value and check if the result is valid SAS code.
data names_data;
length Name $5;
do _n_ = 1 to countw("AAA", "BBB", "CCC", ',');
Name = scan(""AAA", "BBB", "CCC"", _n_, ',');
output;
end;
run;
So the COUNTW() function call has way too many arguments.
Let's add spaces to the SCAN() function call
scan("" AAA ", " BBB ", " CCC "", _n_, ',')
to see how it will be parsed.
The first argument consists of alternating string literals and variable names which is not a valid expression. In addition the variables AAA, BBB, and CCC do not exist.
You can simple use the macro variable to generate the DO statement.
data names_data;
length Name $5;
do Name = &myNames ;
output;
end;
run;
That will generate this valid SAS code.
data names_data;
length Name $5;
do Name = "AAA", "BBB", "CCC" ;
output;
end;
run;
... View more