<?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 - separating values with commas in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-separating-values-with-commas/m-p/65654#M14261</link>
    <description>Chris-&lt;BR /&gt;
&lt;BR /&gt;
Thanks so much for the elegant combination, and  the reference to the paper on macro parameters was exactly what I needed.   Revised code below.&lt;BR /&gt;
&lt;BR /&gt;
Wendy&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%macro addcommas(somevars,addmore);&lt;BR /&gt;
%if %sysevalf(%superq(addmore)=,boolean) %then %let commavalue=%sysfunc(translate(&amp;amp;somevars, %str(,), %str( ) )) ; &lt;BR /&gt;
%else                                          %let commavalue=%sysfunc(translate(&amp;amp;somevars &amp;amp;addmore, %str(,), %str( ) ));&lt;BR /&gt;
%put &amp;amp;commavalue;&lt;BR /&gt;
%mend; &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%addcommas(a b c, d e f) ;&lt;BR /&gt;
a,b,c,d,e,f&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%addcommas(a b c, ) ;&lt;BR /&gt;
a,b,c</description>
    <pubDate>Thu, 20 Aug 2009 17:16:22 GMT</pubDate>
    <dc:creator>WendyT</dc:creator>
    <dc:date>2009-08-20T17:16:22Z</dc:date>
    <item>
      <title>macro - separating values with commas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-separating-values-with-commas/m-p/65652#M14259</link>
      <description>I’m working on a macro that uses DATA steps, PROC TRANSPOSE and PROC SQL. As a consequence of using PROC SQL, I need the same variable list both with and without commas.&lt;BR /&gt;
&lt;BR /&gt;
My original solution was to use %str() and then COMPRESS() inside the macro to get rid of the embedded commas.&lt;BR /&gt;
&lt;BR /&gt;
I would prefer to have the variable list without commas, and to add a second series of variables in some cases.&lt;BR /&gt;
&lt;BR /&gt;
The code below works, but I’m sure there has to be a better method.  Also, is there a way to test if &amp;amp;addmore is null directly?&lt;BR /&gt;
&lt;BR /&gt;
Thanks for any help you can give me.&lt;BR /&gt;
&lt;BR /&gt;
WendyT&lt;BR /&gt;
   &lt;BR /&gt;
&lt;BR /&gt;
%macro addcommas(somevars,addmore);&lt;BR /&gt;
%let nullval =  ;&lt;BR /&gt;
   %if &amp;amp;addmore ne &amp;amp;nullval  %then &lt;BR /&gt;
         %let commavalue=%SYSFUNC(TRANSLATE(&amp;amp;somevars, ', ', ' ')),%SYSFUNC(TRANSLATE(&amp;amp;addmore, ', ', ' '));&lt;BR /&gt;
   %else %let commavalue=%SYSFUNC(TRANSLATE(&amp;amp;somevars, ', ', ' ')) ; &lt;BR /&gt;
%put &amp;amp;commavalue;&lt;BR /&gt;
%mend; &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%addcommas(a b c, d e f) ;&lt;BR /&gt;
a,b,c,d,e,f&lt;BR /&gt;
&lt;BR /&gt;
%addcommas(a b c, ) ;&lt;BR /&gt;
a,b,c</description>
      <pubDate>Wed, 19 Aug 2009 21:10:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-separating-values-with-commas/m-p/65652#M14259</guid>
      <dc:creator>WendyT</dc:creator>
      <dc:date>2009-08-19T21:10:20Z</dc:date>
    </item>
    <item>
      <title>Re: macro - separating values with commas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-separating-values-with-commas/m-p/65653#M14260</link>
      <description>How do you like&lt;BR /&gt;
&lt;BR /&gt;
%macro addcommas(somevars,addmore);&lt;BR /&gt;
  %put %sysfunc(translate(&amp;amp;somevars &amp;amp;addmore, %str(,), %str( ) ));&lt;BR /&gt;
%mend; &lt;BR /&gt;
&lt;BR /&gt;
&amp;gt;Also, is there a way to test if &amp;amp;addmore is null directly?&lt;BR /&gt;
&lt;BR /&gt;
See a very interesting paper on testing for blank macro variables:&lt;BR /&gt;
&lt;A href="http://support.sas.com/resources/papers/proceedings09/022-2009.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings09/022-2009.pdf&lt;/A&gt;</description>
      <pubDate>Wed, 19 Aug 2009 22:52:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-separating-values-with-commas/m-p/65653#M14260</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2009-08-19T22:52:11Z</dc:date>
    </item>
    <item>
      <title>Re: macro - separating values with commas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-separating-values-with-commas/m-p/65654#M14261</link>
      <description>Chris-&lt;BR /&gt;
&lt;BR /&gt;
Thanks so much for the elegant combination, and  the reference to the paper on macro parameters was exactly what I needed.   Revised code below.&lt;BR /&gt;
&lt;BR /&gt;
Wendy&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%macro addcommas(somevars,addmore);&lt;BR /&gt;
%if %sysevalf(%superq(addmore)=,boolean) %then %let commavalue=%sysfunc(translate(&amp;amp;somevars, %str(,), %str( ) )) ; &lt;BR /&gt;
%else                                          %let commavalue=%sysfunc(translate(&amp;amp;somevars &amp;amp;addmore, %str(,), %str( ) ));&lt;BR /&gt;
%put &amp;amp;commavalue;&lt;BR /&gt;
%mend; &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%addcommas(a b c, d e f) ;&lt;BR /&gt;
a,b,c,d,e,f&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%addcommas(a b c, ) ;&lt;BR /&gt;
a,b,c</description>
      <pubDate>Thu, 20 Aug 2009 17:16:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-separating-values-with-commas/m-p/65654#M14261</guid>
      <dc:creator>WendyT</dc:creator>
      <dc:date>2009-08-20T17:16:22Z</dc:date>
    </item>
    <item>
      <title>Re: macro - separating values with commas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-separating-values-with-commas/m-p/65655#M14262</link>
      <description>I don't think you need the %if test Wendy.&lt;BR /&gt;
&lt;BR /&gt;
%sysfunc(translate(&amp;amp;somevars &amp;amp;addmore ...&lt;BR /&gt;
&lt;BR /&gt;
should be enough in all cases. If addmore is empty, translate will not see it.</description>
      <pubDate>Mon, 24 Aug 2009 22:30:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-separating-values-with-commas/m-p/65655#M14262</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2009-08-24T22:30:05Z</dc:date>
    </item>
  </channel>
</rss>

