I always struggle with the macro quoting.
Why does this work and the following modification does not???
%let kept=Arne Bert Hansi;
%macro quote_names(name_list);
%local i name;
%GLOBAL quoted_names;
%let quoted_names = ;
%let i = 1;
%do %while(%scan(&name_list, &i) ne );
%let name = %scan(&name_list, &i);
%let quoted_names = "ed_names %str(%')&name%str(%')%str(, );
%let i = %eval(&i + 1);
%end;
%let quoted_names = %substr("ed_names, 1, %length("ed_names) - 2);
%mend quote_names;
%quote_names(%str(&kept));
%put %STR("ed_names);
'Arne', 'Bert', 'Hansi'
But if I want to leave only the spaces without the comma, then it fails stating
ERROR: Literal contains unmatched quote. ERROR: The macro QUOTE_NAMES will stop executing.
%let kept=Arne Bert Hansi;
%macro quote_names(name_list);
%local i name;
%GLOBAL quoted_names;
%let quoted_names = ;
%let i = 1;
%do %while(%scan(&name_list, &i) ne );
%let name = %scan(&name_list, &i);
%let quoted_names = "ed_names %str(%')&name%str(%')%str( );
%let i = %eval(&i + 1);
%end;
%let quoted_names = %substr("ed_names, 1, %length("ed_names) - 2);
%mend quote_names;
%quote_names(%str(&kept));
%put %STR("ed_names);
... View more