<?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: How to create a macro variable with comma-delimited values from two macro variables? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-with-comma-delimited-values-from/m-p/546347#M151266</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/147980"&gt;@clarkchong1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;That's a great idea! How do one then combine text1 and text2 below to get text3?&lt;BR /&gt;%LET text1 = a b;&lt;BR /&gt;%LET text2 = c d;&lt;BR /&gt;%LET text3 = a b c d;&lt;BR /&gt;Thanks!&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;PRE&gt;%LET text1 = a b;
%LET text2 = c d;
%let text3 = &amp;amp;text1. &amp;amp;text2.;

%put text3= &amp;amp;text3.;&lt;/PRE&gt;</description>
    <pubDate>Tue, 26 Mar 2019 23:04:07 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-03-26T23:04:07Z</dc:date>
    <item>
      <title>How to create a macro variable with comma-delimited values from two macro variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-with-comma-delimited-values-from/m-p/545386#M150860</link>
      <description>&lt;P&gt;I have the following macro variable definitions:&lt;/P&gt;&lt;P&gt;%LET text1 = a;&lt;/P&gt;&lt;P&gt;%LET text2 = %STR(b,c,d);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What do I need to do to create text3 from &amp;amp;text1 and &amp;amp;text2, which is equivalent to assigning:&lt;/P&gt;&lt;P&gt;%LET text3 = %STR(a,b,c,d);&lt;/P&gt;&lt;P&gt;?&lt;/P&gt;&lt;P&gt;I need the resulting text3 to be able to be used as &amp;amp;value in the following sample code:&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/kb/26/155.html" target="_blank"&gt;http://support.sas.com/kb/26/155.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2019 21:59:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-with-comma-delimited-values-from/m-p/545386#M150860</guid>
      <dc:creator>clarkchong1</dc:creator>
      <dc:date>2019-03-22T21:59:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable with comma-delimited values from two macro variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-with-comma-delimited-values-from/m-p/545387#M150861</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%LET text1 = a;

%LET text2 = %STR(b,c,d);

%let text3=%bquote(&amp;amp;text1,&amp;amp;text2);

%put &amp;amp;text3;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%loop(&amp;amp;text3) &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Mar 2019 22:04:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-with-comma-delimited-values-from/m-p/545387#M150861</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-22T22:04:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable with comma-delimited values from two macro variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-with-comma-delimited-values-from/m-p/545391#M150863</link>
      <description>&lt;P&gt;Are you sure you need that particular code?&lt;/P&gt;
&lt;P&gt;You can get the same result without any commas:&lt;/P&gt;
&lt;PRE&gt;%macro loopalt(values);    
                                                                                                                
     /* Count the number of values in the string */                                                                                                                                   
     %let count=%sysfunc(countw(&amp;amp;values)); 

     /* Loop through the total number of values */                                                                                         
     %do i = 1 %to &amp;amp;count;                                                                                                              
      %let value=%scan(&amp;amp;values, &amp;amp;i);                                                                                            
      %put &amp;amp;value;                                                                                                                      
     %end;                                                                                                                                 
%mend;   
%loopalt(2 3 5 7 11 13 17 )&lt;/PRE&gt;
&lt;P&gt;In general introducing commas and/or quotes into macro variables seems to cause more headaches than needed for most cases.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2019 22:16:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-with-comma-delimited-values-from/m-p/545391#M150863</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-03-22T22:16:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable with comma-delimited values from two macro variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-with-comma-delimited-values-from/m-p/545392#M150864</link>
      <description>&lt;P&gt;Why are you adding the macro quotes?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET text2 =1,5,9;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you can use the value a DO statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  do x=&amp;amp;text2;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Mar 2019 22:31:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-with-comma-delimited-values-from/m-p/545392#M150864</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-03-22T22:31:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable with comma-delimited values from two macro variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-with-comma-delimited-values-from/m-p/546328#M151252</link>
      <description>&lt;P&gt;Thanks for the suggestion!&lt;/P&gt;&lt;P&gt;I need to execute a macro functions with various input, with input defined by items in a comma delimited list supplied by the user. So I can't just do it in a data step.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 22:11:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-with-comma-delimited-values-from/m-p/546328#M151252</guid>
      <dc:creator>clarkchong1</dc:creator>
      <dc:date>2019-03-26T22:11:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable with comma-delimited values from two macro variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-with-comma-delimited-values-from/m-p/546329#M151253</link>
      <description>That's a great idea! How do one then combine text1 and text2 below to get text3?&lt;BR /&gt;%LET text1 = a b;&lt;BR /&gt;%LET text2 = c d;&lt;BR /&gt;%LET text3 = a b c d;&lt;BR /&gt;Thanks!</description>
      <pubDate>Tue, 26 Mar 2019 22:18:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-with-comma-delimited-values-from/m-p/546329#M151253</guid>
      <dc:creator>clarkchong1</dc:creator>
      <dc:date>2019-03-26T22:18:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable with comma-delimited values from two macro variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-with-comma-delimited-values-from/m-p/546330#M151254</link>
      <description>This works like magic! Thank you!&lt;BR /&gt;More reference on MACRO quoting: &lt;A href="https://blogs.sas.com/content/sgf/2014/08/15/macro-quoting-made-easy/" target="_blank"&gt;https://blogs.sas.com/content/sgf/2014/08/15/macro-quoting-made-easy/&lt;/A&gt;</description>
      <pubDate>Tue, 26 Mar 2019 22:23:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-with-comma-delimited-values-from/m-p/546330#M151254</guid>
      <dc:creator>clarkchong1</dc:creator>
      <dc:date>2019-03-26T22:23:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable with comma-delimited values from two macro variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-with-comma-delimited-values-from/m-p/546347#M151266</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/147980"&gt;@clarkchong1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;That's a great idea! How do one then combine text1 and text2 below to get text3?&lt;BR /&gt;%LET text1 = a b;&lt;BR /&gt;%LET text2 = c d;&lt;BR /&gt;%LET text3 = a b c d;&lt;BR /&gt;Thanks!&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;PRE&gt;%LET text1 = a b;
%LET text2 = c d;
%let text3 = &amp;amp;text1. &amp;amp;text2.;

%put text3= &amp;amp;text3.;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Mar 2019 23:04:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-with-comma-delimited-values-from/m-p/546347#M151266</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-03-26T23:04:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable with comma-delimited values from two macro variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-with-comma-delimited-values-from/m-p/546503#M151325</link>
      <description>&lt;P&gt;Ah. That's obvious, wasn't it? Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 14:21:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-with-comma-delimited-values-from/m-p/546503#M151325</guid>
      <dc:creator>clarkchong1</dc:creator>
      <dc:date>2019-03-27T14:21:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable with comma-delimited values from two macro variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-with-comma-delimited-values-from/m-p/574832#M162496</link>
      <description>&lt;P&gt;It's even simpler than that. You can have&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let text1 = 2;&lt;BR /&gt;%let text2 = 3,5,7,11,13,17;&lt;BR /&gt;%let text3 = &amp;amp;text1,&amp;amp;text2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To check it out just run&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%put &amp;amp;text3;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and you will get in SAS log:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2,3,5,7,11,13,17&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2019 00:25:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-with-comma-delimited-values-from/m-p/574832#M162496</guid>
      <dc:creator>LeonidBatkhan</dc:creator>
      <dc:date>2019-07-19T00:25:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a macro variable with comma-delimited values from two macro variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-with-comma-delimited-values-from/m-p/574856#M162500</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/147980"&gt;@clarkchong1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for the suggestion!&lt;/P&gt;
&lt;P&gt;I need to execute a macro functions with various input, with input defined by items in a comma delimited list supplied by the user. So I can't just do it in a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I hate commas in macro lists, especially if that list is then a parameter to another macro or macro function.&amp;nbsp; It's nothing but headaches.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You said "comma delimited list supplied by the user":&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) Is that a macro variable supplied by the user, or some other "list"?&lt;/P&gt;
&lt;P&gt;2) Can the user supply it as just a delimited (space or some other character) list?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I prefer "injecting" commas at "run time" via the %seplist macro:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/scottbass/SAS/blob/master/Macro/seplist.sas" target="_blank"&gt;https://github.com/scottbass/SAS/blob/master/Macro/seplist.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are some sample invocations:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %seplist(a b c);
%put %seplist(a b c,nest=q);
%put %seplist(a b c,nest=qq);
%put %seplist(a b c,prefix=a.),%seplist(d e f,prefix=b.);  * say for a SQL SELECT column list ;
%put %seplist(%bquote(a,b,c),indlm=%str(,));  * if you insist on embedded commas then you have to quote the argument ;
%put %seplist(hello scott^how are you^i am well thanks,indlm=^);  * if items contain spaces ;
%put %seplist(hello scott^how are you^i am well thanks,indlm=^,dlm=|);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2019 02:02:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-macro-variable-with-comma-delimited-values-from/m-p/574856#M162500</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-07-19T02:02:16Z</dc:date>
    </item>
  </channel>
</rss>

