<?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 replace commas in a macro variable and put spaces in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/replace-commas-in-a-macro-variable-and-put-spaces/m-p/357639#M84004</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a macro variable like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let have = a,b,c;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and i want a macro withour those commas&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let want = %sysfun(tranwrd(&amp;amp;have,',',' ');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and this is not working.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;caould you please suggest?&lt;/P&gt;</description>
    <pubDate>Wed, 10 May 2017 19:14:47 GMT</pubDate>
    <dc:creator>kumarK</dc:creator>
    <dc:date>2017-05-10T19:14:47Z</dc:date>
    <item>
      <title>replace commas in a macro variable and put spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-commas-in-a-macro-variable-and-put-spaces/m-p/357639#M84004</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a macro variable like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let have = a,b,c;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and i want a macro withour those commas&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let want = %sysfun(tranwrd(&amp;amp;have,',',' ');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and this is not working.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;caould you please suggest?&lt;/P&gt;</description>
      <pubDate>Wed, 10 May 2017 19:14:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-commas-in-a-macro-variable-and-put-spaces/m-p/357639#M84004</guid>
      <dc:creator>kumarK</dc:creator>
      <dc:date>2017-05-10T19:14:47Z</dc:date>
    </item>
    <item>
      <title>Re: replace commas in a macro variable and put spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-commas-in-a-macro-variable-and-put-spaces/m-p/357642#M84005</link>
      <description>&lt;P&gt;Several problems wrong function: sysfunC not sysfun Translate is the function to change single characters, Tranwrd is intended for groups of characters, And since your value has , imbedded they become parameters to the functions and through things off, hence %quote.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let have = a,b,c;

%let want = %sysfunc(translate(%quote(&amp;amp;have),' ',','));

%put &amp;amp;have &amp;amp;want;
&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 May 2017 19:22:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-commas-in-a-macro-variable-and-put-spaces/m-p/357642#M84005</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-05-10T19:22:04Z</dc:date>
    </item>
    <item>
      <title>Re: replace commas in a macro variable and put spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-commas-in-a-macro-variable-and-put-spaces/m-p/357855#M84053</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let have = a,b,c;

%let want=%sysfunc(translate(%bquote(&amp;amp;have),%str( ),%str(,)));

%put &amp;amp;want;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 May 2017 12:42:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-commas-in-a-macro-variable-and-put-spaces/m-p/357855#M84053</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-05-11T12:42:15Z</dc:date>
    </item>
    <item>
      <title>Re: replace commas in a macro variable and put spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-commas-in-a-macro-variable-and-put-spaces/m-p/357872#M84060</link>
      <description>&lt;P&gt;First let's clean up the obvious typos in your posted code and try it.&lt;/P&gt;
&lt;PRE&gt;2129  %let have = a,b,c;
2130  %let want = %sysfunc(tranwrd(&amp;amp;have,',',' '));
ERROR: The function TRANWRD referenced by the %SYSFUNC or %QSYSFUNC macro function has too many
       arguments.&lt;/PRE&gt;
&lt;P&gt;Because &amp;amp;HAVE contains commas the TRANWRD() function is seeing way too many commas. You can add some macro quoting to prevent that.&lt;/P&gt;
&lt;PRE&gt;2134  %let have = a,b,c;
2135  %let want = %sysfunc(tranwrd(%quote(&amp;amp;have),',',' '));
2136  %put &amp;amp;=want;
WANT=a,b,c&lt;/PRE&gt;
&lt;P&gt;But notice that it did not change anything. That is because your macro variable does not contain the any commas that are enclosed in single quotes. Since to macro code everthing is a character string you do not need to use quotes around string literals. &amp;nbsp;But you will need to macro quote both commas and spaces to get them to be treated as text instead of delimiters.&lt;/P&gt;
&lt;PRE&gt;2137  %let have = a,b,c;
2138  %let want = %sysfunc(tranwrd(%quote(&amp;amp;have),%str(,),%str( )));
2139  %put &amp;amp;=want;
WANT=a b c&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2017 13:13:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-commas-in-a-macro-variable-and-put-spaces/m-p/357872#M84060</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-05-11T13:13:00Z</dc:date>
    </item>
  </channel>
</rss>

