<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: macro quoting issue for list of values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-quoting-issue-for-list-of-values/m-p/963323#M375322</link>
    <description>&lt;P&gt;One more option just for fun, with FCMP function called in %SYSFUNC()&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fcmp outlib=work.f.p;
function addQuotes(str $,s $, q) $ 32767;
    length result $ 32767 sep word Usep $ 128 qt $ 1;
    sep = s;
    Usep = upcase(sep); 

    select;
      when (Usep=" ")  sep=" ";
      when (Usep="C")  sep=",";
      when (Usep="SC") sep=";";
      when (Usep="P")  sep=".";
      when (Usep=:"S") sep=substr(sep,2); /* string up to 127 bytes */
      otherwise sep = " ";
    end;

    select(q);
      when(2)   qt='"';
      when(1)   qt="'";
      otherwise qt=" ";
    end;

    quit=0;
    do i = 1 by 1 while(NOT quit);
      word = scan(str, i, " ");
      if NOT missing(word) then 
        do;
          if NOT (qt=" ") then word=quote(strip(word),qt);
          result = catX(ifc(sep=" "," ",strip(sep)), result, strip(word));
        end;
      else quit=1;
    end;
    return(result);
endfunc;
quit;

options cmplib=work.f;


%let kept=Arne Bert Hansi;

%put %sysfunc(addQuotes(&amp;amp;kept.,C,2));
%put %sysfunc(addQuotes(&amp;amp;kept.,S!,0));

data _null_;
  kept="Arne Bert Hansi";
  str=addQuotes(kept,"C",2);
  put kept= / str=;

  str=addQuotes(kept,"SC",0);
  put kept= / str=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
    <pubDate>Thu, 03 Apr 2025 14:40:59 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2025-04-03T14:40:59Z</dc:date>
    <item>
      <title>macro quoting issue for list of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-quoting-issue-for-list-of-values/m-p/963304#M375308</link>
      <description>&lt;P&gt;I always struggle with the macro quoting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why does this work and the following modification does not???&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%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(&amp;amp;name_list, &amp;amp;i) ne );
        %let name = %scan(&amp;amp;name_list, &amp;amp;i);
        %let quoted_names = &amp;amp;quoted_names %str(%')&amp;amp;name%str(%')%str(, );
        %let i = %eval(&amp;amp;i + 1);
    %end;
    %let quoted_names = %substr(&amp;amp;quoted_names, 1, %length(&amp;amp;quoted_names) - 2);

%mend quote_names;

%quote_names(%str(&amp;amp;kept));

%put %STR(&amp;amp;quoted_names);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;'Arne', 'Bert', 'Hansi'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if I want to leave only the spaces without the comma, then it fails stating&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;ERROR: Literal contains unmatched quote.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;ERROR: The macro QUOTE_NAMES will stop executing.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%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(&amp;amp;name_list, &amp;amp;i) ne );
        %let name = %scan(&amp;amp;name_list, &amp;amp;i);
        %let quoted_names = &amp;amp;quoted_names %str(%')&amp;amp;name%str(%')%str( );
        %let i = %eval(&amp;amp;i + 1);
    %end;
    %let quoted_names = %substr(&amp;amp;quoted_names, 1, %length(&amp;amp;quoted_names) - 2);

%mend quote_names;

%quote_names(%str(&amp;amp;kept));

%put %STR(&amp;amp;quoted_names);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Apr 2025 11:01:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-quoting-issue-for-list-of-values/m-p/963304#M375308</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2025-04-03T11:01:37Z</dc:date>
    </item>
    <item>
      <title>Re: macro quoting issue for list of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-quoting-issue-for-list-of-values/m-p/963305#M375309</link>
      <description>&lt;P&gt;You might want to use the &lt;A href="https://github.com/sasutils/macros/blob/master/qlist.sas" target="_self"&gt;%QLIST macro&lt;/A&gt;, which is much easier than writing your own macro. I have used %QLIST for years and it works as desired.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your particular problem can be solved by using %UNQUOTE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    %let quoted_names = %unquote(%substr(&amp;amp;quoted_names, 1, %length(&amp;amp;quoted_names) - 2));
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why does %UNQUOTE work here? I have trouble explaining it other than to say when it looks like you have coded everything properly and you still get errors, and it usually involves a case where you created a quoted string in the macro, try %UNQUOTE. Or perhaps Mr.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;can explain, you can search for his explanation of this in previous threads, or buy his book (the name of which I have forgotten) which also explains.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Apr 2025 12:06:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-quoting-issue-for-list-of-values/m-p/963305#M375309</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-04-03T12:06:01Z</dc:date>
    </item>
    <item>
      <title>Re: macro quoting issue for list of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-quoting-issue-for-list-of-values/m-p/963307#M375310</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/127222"&gt;@acordes&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/127222"&gt;@acordes&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Why does this work and the following modification does not???&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is because you left the final %LET statement in the macro, which had the purpose of deleting the unwanted&amp;nbsp;&lt;FONT face="courier new,courier"&gt;%str(, )&lt;/FONT&gt; after the last word, but which in the modified macro deletes the unwanted trailing blank &lt;EM&gt;plus the important closing quotation mark&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Solution: Delete that final %LET statement entirely and also the trailing&amp;nbsp;&lt;FONT face="courier new,courier"&gt;%str( )&lt;/FONT&gt; earlier in the code. (Note that you already get the separating blanks by inserting them&amp;nbsp;&lt;EM&gt;before&lt;/EM&gt; the newly appended name -- and the %LET statement automatically avoids creating a leading blank before the first name.)&lt;/P&gt;</description>
      <pubDate>Thu, 03 Apr 2025 11:58:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-quoting-issue-for-list-of-values/m-p/963307#M375310</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2025-04-03T11:58:40Z</dc:date>
    </item>
    <item>
      <title>Re: macro quoting issue for list of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-quoting-issue-for-list-of-values/m-p/963310#M375313</link>
      <description>&lt;P&gt;do you need macro for the process?&lt;/P&gt;
&lt;P&gt;how about data step?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let kept=Arne Bert Hansi;

data _null_;
length str result $ 32767 word $ 128;
  str=symget('kept');
  sep = " "; /* space, but you can set whatever you like */

  do i=1 by 1 while(NOT quit);
    word = scan(str, i, " ");
    if word NE " " then result = catX(sep, result, quote(strip(word)) );
                   else quit=1;
  end;
  call symputX("quoted_names", result, "G");
run;

%put &amp;amp;quoted_names.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Thu, 03 Apr 2025 12:23:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-quoting-issue-for-list-of-values/m-p/963310#M375313</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2025-04-03T12:23:05Z</dc:date>
    </item>
    <item>
      <title>Re: macro quoting issue for list of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-quoting-issue-for-list-of-values/m-p/963311#M375314</link>
      <description>&lt;P&gt;O course DoSubL() function can help in wrapping it into a macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let kept=Arne Bert Hansi;

%macro addQuotes(kept);
%local rc quoted_names;
%let rc=%sysfunc(dosubl(%str(
  data _null_;
    length str result $ 32767 word $ 128;
    str=symget("kept");
    sep = " "; /* space */

    do i=1 by 1 while(NOT quit);
      word = scan(str, i, " ");
      if word NE " " then result = catX(sep, result, quote(strip(word)) );
                     else quit=1;
    end;
    call symputX("quoted_names", result, "L");
  run;
)));
&amp;amp;quoted_names.
%mend addQuotes;

%put %addQuotes(&amp;amp;kept.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Thu, 03 Apr 2025 12:29:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-quoting-issue-for-list-of-values/m-p/963311#M375314</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2025-04-03T12:29:49Z</dc:date>
    </item>
    <item>
      <title>Re: macro quoting issue for list of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-quoting-issue-for-list-of-values/m-p/963314#M375317</link>
      <description>&lt;P&gt;I find it usually works better to only add the separator before the next word.&lt;/P&gt;
&lt;P&gt;Also an iterative DO loop are much,much easier to code and understand than a DO WHILE loop where you have to manually increment the counter.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro quote_names(name_list);
  %local i name sep;
  %GLOBAL quoted_names;
  %let quoted_names = ;
  %let sep=;
  %do i=1 %to %sysfunc(countw(&amp;amp;name_list,%str( )));
    %let name = %scan(&amp;amp;name_list, &amp;amp;i,%str( ));
    %let quoted_names = &amp;amp;quoted_names.&amp;amp;sep.%str(%')&amp;amp;name%str(%');
    %let sep = %str(, );
  %end;
  %let quoted_names = %unquote(&amp;amp;quoted_names);
%mend quote_names;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Let's try it out.&lt;/P&gt;
&lt;PRE&gt;14   %quote_names(a b);
15   %put |&amp;amp;quoted_names|;
|'a', 'b'|
16   %quote_names( );
17   %put |&amp;amp;quoted_names|;
||
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Apr 2025 12:56:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-quoting-issue-for-list-of-values/m-p/963314#M375317</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-04-03T12:56:05Z</dc:date>
    </item>
    <item>
      <title>Re: macro quoting issue for list of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-quoting-issue-for-list-of-values/m-p/963317#M375319</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;, thanks for the mention.&amp;nbsp; Unfortunately the book "Macro Language Magic" is now out of print, and I have been retired and without SAS for more than 5 years now.&lt;/P&gt;
&lt;P&gt;Off the top of my head, the most common "mysterious" need for %unquote is when macro language creates a list of quoted items for use in a WHERE clause within SQL code.&amp;nbsp; Many times the software figures out to unquote a list, but not when SQL is involved.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Apr 2025 13:15:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-quoting-issue-for-list-of-values/m-p/963317#M375319</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2025-04-03T13:15:02Z</dc:date>
    </item>
    <item>
      <title>Re: macro quoting issue for list of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-quoting-issue-for-list-of-values/m-p/963319#M375320</link>
      <description>&lt;P&gt;Book still appears to be on sale at Amazon.&amp;nbsp;&lt;A href="https://www.amazon.com/SAS-Macro-Language-Magic-Discovering/dp/1612907105" target="_blank"&gt;https://www.amazon.com/SAS-Macro-Language-Magic-Discovering/dp/1612907105&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Apr 2025 13:52:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-quoting-issue-for-list-of-values/m-p/963319#M375320</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-04-03T13:52:51Z</dc:date>
    </item>
    <item>
      <title>Re: macro quoting issue for list of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-quoting-issue-for-list-of-values/m-p/963322#M375321</link>
      <description>&lt;P&gt;Hey &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/127222"&gt;@acordes&lt;/a&gt;! I've got a macro and a function called cquote that was greatly inspired by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;'s work and it has served me well over the years:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/stu-code/sas/blob/master/utility-macros/cquote.sas" target="_blank"&gt;https://github.com/stu-code/sas/blob/master/utility-macros/cquote.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro cquote(strlist, quote);
    %if(%upcase(&amp;amp;quote) = SINGLE) %then %let q = %str(%');
        %else %let q = %str(%");

    %unquote(%bquote(&amp;amp;q)%qsysfunc(tranwrd(%qsysfunc(compbl(%superq(strlist))),%bquote( ),%bquote(&amp;amp;q,&amp;amp;q)))%bquote(&amp;amp;q))
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fcmp outlib=work.funcs.str;

    /* Double quote version */
    function cquote(str$) $200;
        return (cats('"', tranwrd(compbl(str),' ','","'), '"'));
    endfunc;

    /* Single quote version */ 
    function scquote(str$) $200;
        return (cats("'", tranwrd(compbl(str),' ',"','"), "'"));
    endfunc;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can give these a try as well.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Apr 2025 14:23:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-quoting-issue-for-list-of-values/m-p/963322#M375321</guid>
      <dc:creator>Stu_SAS</dc:creator>
      <dc:date>2025-04-03T14:23:57Z</dc:date>
    </item>
    <item>
      <title>Re: macro quoting issue for list of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-quoting-issue-for-list-of-values/m-p/963323#M375322</link>
      <description>&lt;P&gt;One more option just for fun, with FCMP function called in %SYSFUNC()&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fcmp outlib=work.f.p;
function addQuotes(str $,s $, q) $ 32767;
    length result $ 32767 sep word Usep $ 128 qt $ 1;
    sep = s;
    Usep = upcase(sep); 

    select;
      when (Usep=" ")  sep=" ";
      when (Usep="C")  sep=",";
      when (Usep="SC") sep=";";
      when (Usep="P")  sep=".";
      when (Usep=:"S") sep=substr(sep,2); /* string up to 127 bytes */
      otherwise sep = " ";
    end;

    select(q);
      when(2)   qt='"';
      when(1)   qt="'";
      otherwise qt=" ";
    end;

    quit=0;
    do i = 1 by 1 while(NOT quit);
      word = scan(str, i, " ");
      if NOT missing(word) then 
        do;
          if NOT (qt=" ") then word=quote(strip(word),qt);
          result = catX(ifc(sep=" "," ",strip(sep)), result, strip(word));
        end;
      else quit=1;
    end;
    return(result);
endfunc;
quit;

options cmplib=work.f;


%let kept=Arne Bert Hansi;

%put %sysfunc(addQuotes(&amp;amp;kept.,C,2));
%put %sysfunc(addQuotes(&amp;amp;kept.,S!,0));

data _null_;
  kept="Arne Bert Hansi";
  str=addQuotes(kept,"C",2);
  put kept= / str=;

  str=addQuotes(kept,"SC",0);
  put kept= / str=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Thu, 03 Apr 2025 14:40:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-quoting-issue-for-list-of-values/m-p/963323#M375322</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2025-04-03T14:40:59Z</dc:date>
    </item>
    <item>
      <title>Re: macro quoting issue for list of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-quoting-issue-for-list-of-values/m-p/963327#M375323</link>
      <description>&lt;P&gt;Yet another approach: see Richard DeVenezia's %seplist() macro.&amp;nbsp; It takes a list of items, and allows you to add quotes, or delimiters, or prefixes/suffixes, and more.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://www.devenezia.com/downloads/sas/macros/index.php?m=seplist" target="_blank"&gt;https://www.devenezia.com/downloads/sas/macros/index.php?m=seplist&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Apr 2025 14:58:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-quoting-issue-for-list-of-values/m-p/963327#M375323</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2025-04-03T14:58:31Z</dc:date>
    </item>
    <item>
      <title>Re: macro quoting issue for list of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-quoting-issue-for-list-of-values/m-p/963328#M375324</link>
      <description>&lt;P&gt;You could also do this, for with and without commas, respectively:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
call symputx("w_commas",tranwrd(quote(tranwrd("&amp;amp;kept",' ',quote(', '))),'""','"'));
call symputx("wo_commas",tranwrd(quote(tranwrd("&amp;amp;kept",' ',quote(' '))),'""','"'));
run;

%put &amp;amp;=w_commas;
%put &amp;amp;=wo_commas;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;DIV class="sasSource"&gt;W_COMMAS="Arne", "Bert", "Hansi"&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;WO_COMMAS="Arne" "Bert" "Hansi"&lt;/DIV&gt;</description>
      <pubDate>Thu, 03 Apr 2025 15:07:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-quoting-issue-for-list-of-values/m-p/963328#M375324</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2025-04-03T15:07:03Z</dc:date>
    </item>
    <item>
      <title>Re: macro quoting issue for list of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-quoting-issue-for-list-of-values/m-p/963406#M375337</link>
      <description>&lt;P&gt;No need macro.&lt;/P&gt;
&lt;P&gt;Perl Regular Expression is more than suffice.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let kept=Arne Bert Hansi;

&lt;STRONG&gt;%let want1=%str(%')%qsysfunc(prxchange(s/\s+/','/,-1,&amp;amp;kept.))%str(%');
%let want2=%str(%')%qsysfunc(prxchange(s/\s+/' '/,-1,&amp;amp;kept.))%str(%');
%put &amp;amp;=want1.;
%put &amp;amp;=want2.;&lt;/STRONG&gt;


%let want3="%sysfunc(prxchange(s/\s+/"%str(,)"/,-1,&amp;amp;kept.))";
%let want4="%sysfunc(prxchange(s/\s+/" "/,-1,&amp;amp;kept.))";
%put &amp;amp;=want3.;
%put &amp;amp;=want4.;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;1    %let kept=Arne Bert Hansi;
2
3    %let want1=%str(%')%qsysfunc(prxchange(s/\s+/','/,-1,&amp;amp;kept.))%str(%');
4    %let want2=%str(%')%qsysfunc(prxchange(s/\s+/' '/,-1,&amp;amp;kept.))%str(%');
5    %put &amp;amp;=want1.;
WANT1='Arne','Bert','Hansi'
6    %put &amp;amp;=want2.;
WANT2='Arne' 'Bert' 'Hansi'
7
8
9    %let want3="%sysfunc(prxchange(s/\s+/"%str(,)"/,-1,&amp;amp;kept.))";
10   %let want4="%sysfunc(prxchange(s/\s+/" "/,-1,&amp;amp;kept.))";
11   %put &amp;amp;=want3.;
WANT3="Arne","Bert","Hansi"
12   %put &amp;amp;=want4.;
WANT4="Arne" "Bert" "Hansi"

&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Apr 2025 12:12:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-quoting-issue-for-list-of-values/m-p/963406#M375337</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-04-04T12:12:26Z</dc:date>
    </item>
    <item>
      <title>Re: macro quoting issue for list of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-quoting-issue-for-list-of-values/m-p/963423#M375339</link>
      <description>&lt;P&gt;Multiple spaces can be a bit of a problem here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let kept=Arne    Bert  Hansi;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;gives&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;46   data _null_;
47   call symputx("w_commas",tranwrd(quote(tranwrd("&amp;amp;kept",' ',quote(', '))),'""','"'));
48   call symputx("wo_commas",tranwrd(quote(tranwrd("&amp;amp;kept",' ',quote(' '))),'""','"'));
49   run;

NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


50
51   %put &amp;amp;=w_commas;
W_COMMAS="Arne", "", "", "", "Bert", "", "Hansi"
52   %put &amp;amp;=wo_commas;
WO_COMMAS="Arne" "" "" "" "Bert" "" "Hansi"
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Fri, 04 Apr 2025 14:19:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-quoting-issue-for-list-of-values/m-p/963423#M375339</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2025-04-04T14:19:15Z</dc:date>
    </item>
    <item>
      <title>Re: macro quoting issue for list of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-quoting-issue-for-list-of-values/m-p/963425#M375340</link>
      <description>Sure, so just wrap &amp;amp;kept in %cmpres( ) within the syntax above.</description>
      <pubDate>Fri, 04 Apr 2025 14:22:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-quoting-issue-for-list-of-values/m-p/963425#M375340</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2025-04-04T14:22:03Z</dc:date>
    </item>
    <item>
      <title>Re: macro quoting issue for list of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-quoting-issue-for-list-of-values/m-p/963429#M375341</link>
      <description>&lt;P&gt;or compbl() function&lt;/P&gt;</description>
      <pubDate>Fri, 04 Apr 2025 14:53:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-quoting-issue-for-list-of-values/m-p/963429#M375341</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2025-04-04T14:53:41Z</dc:date>
    </item>
  </channel>
</rss>

