<?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 var list in a macro? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-var-list-in-a-macro/m-p/879538#M347471</link>
    <description>&lt;P&gt;Thank you very much. That helped me a lot and it's working for my requirement.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 07 Jun 2023 13:24:55 GMT</pubDate>
    <dc:creator>Moksha</dc:creator>
    <dc:date>2023-06-07T13:24:55Z</dc:date>
    <item>
      <title>How to create a var list in a macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-var-list-in-a-macro/m-p/879521#M347458</link>
      <description>&lt;P&gt;Hi All, I have a macro which takes a list of variables say var1, var2, var3, var4, var5 and var6 as a parameter as shown the code below . In need to create a new variable say varlist containing these input variables separated by commas, without any quotation marks. I have tried it as follows, but it is not working :&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro(vars= var1 var2 var3 var4 var5 var6);
%let varcount = %sysfunc(countw(&amp;amp;amp;vars));

%let varlist=;
%do i = 1 %to &amp;amp;amp;varcount;
       %let varname = %qscan(&amp;amp;amp;vars,&amp;amp;amp;i);
       %let var&amp;amp;amp;i = &amp;amp;amp;varname;
       %let varlist = %unquote(%sysfunc(catx(',', &amp;amp;amp;varlist, &amp;amp;amp;&amp;amp;amp;var&amp;amp;amp;i)));
        %put var list is &amp;amp;amp;varlist;

%mend;

In the following NOTE is there in the log:
NOTE: Line generated by the macro variable "VARLIST"
1                   var1','var2','var3','var4','var5','var6&lt;/PRE&gt;
&lt;P&gt;Please, advise how achieve the result as var1,var2,var3,var4,var5,var6&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jun 2023 12:15:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-var-list-in-a-macro/m-p/879521#M347458</guid>
      <dc:creator>Moksha</dc:creator>
      <dc:date>2023-06-07T12:15:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a var list in a macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-var-list-in-a-macro/m-p/879523#M347460</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let varlist=var1 var2 var3 var4 var5 var6;
%let varlist_wanted=%sysfunc(translate(&amp;amp;varlist,%str(,),%str( )));
%put &amp;amp;=varlist_wanted;
&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;However, I should point out that if you don't want spaces and you do want commas, you probably should NOT create the macro variable with spaces in the first place; create it with commas and then you don't need the above code.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jun 2023 12:31:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-var-list-in-a-macro/m-p/879523#M347460</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-06-07T12:31:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a var list in a macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-var-list-in-a-macro/m-p/879526#M347462</link>
      <description>Thank you very much. It's working. Can you please help me how to get the out as
varlist_wanted = 'var1', 'var2', 'var3', 'var4', 'var5', 'var6'</description>
      <pubDate>Wed, 07 Jun 2023 12:45:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-var-list-in-a-macro/m-p/879526#M347462</guid>
      <dc:creator>Moksha</dc:creator>
      <dc:date>2023-06-07T12:45:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a var list in a macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-var-list-in-a-macro/m-p/879527#M347463</link>
      <description>&lt;P&gt;See this:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Quoting/m-p/877543#M346659" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Quoting/m-p/877543#M346659&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;and also this:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Quoting/m-p/877567#M346675" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Quoting/m-p/877567#M346675&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jun 2023 12:47:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-var-list-in-a-macro/m-p/879527#M347463</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-06-07T12:47:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a var list in a macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-var-list-in-a-macro/m-p/879531#M347467</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/439180"&gt;@Moksha&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you very much. It's working. Can you please help me how to get the out as varlist_wanted = 'var1', 'var2', 'var3', 'var4', 'var5', 'var6'&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Do you actually need single quotes (are you using the macro to generate SQL code in some external database) or are double quotes ok (are you using the macro to generate SAS code)?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro qlist(vars);
%local i sep word;
%do i = 1 %to %sysfunc(countw(&amp;amp;vars,%str( )));
  %let word=%scan(&amp;amp;vars,&amp;amp;i,%str( ));
&amp;amp;sep."&amp;amp;word"
  %let sep=,;
%end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Example usage:&lt;/P&gt;
&lt;PRE&gt;21   %let varlist=%qlist(vars= var1 var2 var3 var4 var5 var6);
22   %put &amp;amp;=varlist;
VARLIST='var1' ,'var2' ,'var3' ,'var4' ,'var5' ,'var6'
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need the single quotes you could use the QUOTE() function to add them.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;sep.%sysfunc(quote(&amp;amp;word,%str(%')))
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;There is a more robust version of &lt;A href="https://github.com/sasutils/macros/blob/master/qlist.sas" target="_self"&gt;%QLIST()&lt;/A&gt; available on-line.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jun 2023 12:58:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-var-list-in-a-macro/m-p/879531#M347467</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-06-07T12:58:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a var list in a macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-var-list-in-a-macro/m-p/879533#M347468</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
call symputx('varlist',translate(compress("&amp;amp;vars.","'")," ",","));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;No macro and no looping needed.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jun 2023 13:10:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-var-list-in-a-macro/m-p/879533#M347468</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-06-07T13:10:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a var list in a macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-var-list-in-a-macro/m-p/879535#M347470</link>
      <description>&lt;P&gt;This kind of need comes up a lot in the macro language.&amp;nbsp; I have a list of &amp;lt;variables|values|dataset names&amp;gt; and I need to &amp;lt;add|remove|change&amp;gt;&amp;nbsp; a &amp;lt;delimiter|quotes|brackets&amp;gt;.&amp;nbsp; You might want to look into using a utility macro for this sort of manipulation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm a fan of Richard Devenezia's %seplist:&amp;nbsp;&amp;nbsp;&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jun 2023 13:08:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-var-list-in-a-macro/m-p/879535#M347470</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-06-07T13:08:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a var list in a macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-var-list-in-a-macro/m-p/879538#M347471</link>
      <description>&lt;P&gt;Thank you very much. That helped me a lot and it's working for my requirement.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jun 2023 13:24:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-var-list-in-a-macro/m-p/879538#M347471</guid>
      <dc:creator>Moksha</dc:creator>
      <dc:date>2023-06-07T13:24:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a var list in a macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-var-list-in-a-macro/m-p/879544#M347475</link>
      <description>&lt;P&gt;Thank you very much Tom. This is working and I will use this as the code is small. As mentioned by PaigeMiller and you, the Qlist() macro available at github is more sophisticated and it's also working for my requirement. I am really learning new concepts and different ways to solve a problem, in this forum. It's really very helpful. I thank each and everyone who responded.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I didn't understand&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;amp;sep."&amp;amp;word"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;why it is without semicolon ; and why it is before&amp;nbsp;&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt; %let sep=,;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Can you please clarify?&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jun 2023 13:58:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-var-list-in-a-macro/m-p/879544#M347475</guid>
      <dc:creator>Moksha</dc:creator>
      <dc:date>2023-06-07T13:58:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a var list in a macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-var-list-in-a-macro/m-p/879624#M347509</link>
      <description>&lt;P&gt;Thank you very much for providing such a valuable information. I will use this wherever applicable.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jun 2023 17:51:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-var-list-in-a-macro/m-p/879624#M347509</guid>
      <dc:creator>Moksha</dc:creator>
      <dc:date>2023-06-07T17:51:38Z</dc:date>
    </item>
  </channel>
</rss>

