As folks have said, the SAS macro processor is just a tool for generating SAS code. It controls the code that gets sent to the SAS compiler.
I like to think of it as analogous to compiler directives in other languages, such as C:
https://www.cs.auckland.ac.nz/references/unix/digital/AQTLTBTE/DOCU_078.HTM
The analogy isn't exact, but works for me to help me understand SAS macro processing. YMMV.
As others have also said, commas in your macro variables can be problematic, especially if that macro variable is passed to another macro or macro function. This is because macro is just text, and commas are delimiters for macro parameters.
I also don't like to include syntax in my macro variables, i.e. commas, parentheses, quotes, etc. Instead, I like to only include the data in the macro variable, then "inject" the syntax at the point where the macro variable is referenced.
An example:
* a list of names ;
* notice the list is space separated, not comma separated ;
%let list = Alfred Henry John Philip;
* it is easy to parse this list ;
%macro test;
%let i=1;
%let word=%scan(&list,&i,%str( ));
%do %while (&word ne );
%put &=word;
%let i=%eval(&i+1);
%let word=%scan(&list,&i,%str( ));
%end;
%mend;
%test
* an alternative is to use my %loop macro, ;
* which encapsulates the list parsing and calls a child macro ;
* for every token in the list ;
%macro code;
%put &=word;
%mend;
%loop(&list)
* use the seplist macro to "inject" syntax when the list is referenced ;
%put %seplist(&list);
%put %seplist(&list,nest=q);
%put %seplist(&list,nest=qq);
%put %seplist(&list,dlm=|);
* so, injecting the syntax at "runtime" ;
data class_subset;
set sashelp.class;
where name in (%seplist(&list,nest=qq));
run;
* for RBDMS's, sometimes you need a macro variable to be single quoted ;
%let foo=bar;
%put %squote(&foo);
* or you could also use %seplist for a single token only ;
%put %seplist(&foo,nest=q);
Credit for the %squote macro goes to @Tom , see the macro header for details.
https://github.com/scottbass/SAS/blob/master/Macro/loop.sas
https://github.com/scottbass/SAS/blob/master/Macro/seplist.sas
https://github.com/scottbass/SAS/blob/master/Macro/squote.sas
https://github.com/scottbass/SAS/blob/master/Macro/parmv.sas
... View more