<?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: Create a macro variable consisting of a list SAS variable names, how to do it? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-consisting-of-a-list-SAS-variable-names/m-p/131610#M26816</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would like to use the name list in a summary function in a proc sql such as&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select sum(0,&amp;amp;varlist) as amounts&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That is the reason I like comma as seperator.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 08 Sep 2013 05:56:14 GMT</pubDate>
    <dc:creator>Macro</dc:creator>
    <dc:date>2013-09-08T05:56:14Z</dc:date>
    <item>
      <title>Create a macro variable consisting of a list SAS variable names, how to do it?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-consisting-of-a-list-SAS-variable-names/m-p/131600#M26806</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know the list of SAS variables are: amount1, amount2, ..., amountj. How can I create a macro variable (called amounts) storing this list of variables separated by comma, so that I can use this list in future?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if j=20, then, something like amounts = amount1,amount2,...,amount20&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 07 Sep 2013 03:10:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-consisting-of-a-list-SAS-variable-names/m-p/131600#M26806</guid>
      <dc:creator>Macro</dc:creator>
      <dc:date>2013-09-07T03:10:41Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro variable consisting of a list SAS variable names, how to do it?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-consisting-of-a-list-SAS-variable-names/m-p/131601#M26807</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;check the below code&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select name into: vname separated by ',' from dictionary.columns where libname='SASHELP' and memname='CLASS';&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;%put &amp;amp;vname;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Jagadish&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 07 Sep 2013 07:09:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-consisting-of-a-list-SAS-variable-names/m-p/131601#M26807</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2013-09-07T07:09:44Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro variable consisting of a list SAS variable names, how to do it?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-consisting-of-a-list-SAS-variable-names/m-p/131602#M26808</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Jagadish, thanks for the answer. Indeed, I would like to avoid using dictionary.columns since this file is create as an intermediate file and is inside a loop. I don't want repeat this proc sql many times since I know the variable names already. I would like to create this name list before the loop and before the file is created.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So (1) I don't have the file at this stage, so I cannot use dictionary.columns.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (2) I would like to avoid using proc sql in the loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Therefore any other ways?&amp;nbsp; Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 07 Sep 2013 19:15:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-consisting-of-a-list-SAS-variable-names/m-p/131602#M26808</guid>
      <dc:creator>Macro</dc:creator>
      <dc:date>2013-09-07T19:15:43Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro variable consisting of a list SAS variable names, how to do it?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-consisting-of-a-list-SAS-variable-names/m-p/131603#M26809</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you know the names then type them into the %LET statement.&lt;/P&gt;&lt;P&gt;If instead the idea is to create a list of names by incrementing a counter then use a %DO loop&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%do i=1 %to &amp;amp;j;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let varlist=&amp;amp;varlist amount&amp;amp;i ;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you really want commas instead of spaces (but why would you want the commas?) in your list then you could add some extra logic to prevent an extra leading comma.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let varlist=amount1;&lt;/P&gt;&lt;P&gt;%do i=2 %to &amp;amp;j;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let varlist=&amp;amp;varlist,amount&amp;amp;i ;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 07 Sep 2013 19:40:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-consisting-of-a-list-SAS-variable-names/m-p/131603#M26809</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-09-07T19:40:15Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro variable consisting of a list SAS variable names, how to do it?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-consisting-of-a-list-SAS-variable-names/m-p/131604#M26810</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You may not have to do anything at all.&amp;nbsp; Consider this construct:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;amount:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The colon at the end means that this represents a list of variables, all those variable names that begin with "amount".&amp;nbsp; It can be used in both DATA and PROC steps.&amp;nbsp; For example. a DATA step might use:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;array amts {*} amount:;&lt;/P&gt;&lt;P&gt;do i=1 to dim(amts);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 07 Sep 2013 19:40:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-consisting-of-a-list-SAS-variable-names/m-p/131604#M26810</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2013-09-07T19:40:58Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro variable consisting of a list SAS variable names, how to do it?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-consisting-of-a-list-SAS-variable-names/m-p/131605#M26811</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Tom. In your first version with space as delimiter, the &amp;amp;varlist is not initialized, I tried the code and did not work. But second version worked. Does it mean that when using space as delimiter, then the first word in list does not need to be initialized. Can an empty word be used to initialize varlist so that the do loop can start from 1?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 07 Sep 2013 21:12:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-consisting-of-a-list-SAS-variable-names/m-p/131605#M26811</guid>
      <dc:creator>Macro</dc:creator>
      <dc:date>2013-09-07T21:12:26Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro variable consisting of a list SAS variable names, how to do it?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-consisting-of-a-list-SAS-variable-names/m-p/131606#M26812</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Astounding. The data set file containing these names are not availabe at this stage, so I may not be able to use the way you suggested.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 07 Sep 2013 21:15:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-consisting-of-a-list-SAS-variable-names/m-p/131606#M26812</guid>
      <dc:creator>Macro</dc:creator>
      <dc:date>2013-09-07T21:15:04Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro variable consisting of a list SAS variable names, how to do it?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-consisting-of-a-list-SAS-variable-names/m-p/131607#M26813</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Then how about something like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; length vars $32767;&lt;/P&gt;&lt;P&gt;&amp;nbsp; vars='amount1';&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i=2 to 20;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; vars=catx(' ',vars,catt('amount',i));&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; call symput('varlist',vars) ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%put &amp;amp;varlist.;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 07 Sep 2013 22:00:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-consisting-of-a-list-SAS-variable-names/m-p/131607#M26813</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2013-09-07T22:00:08Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro variable consisting of a list SAS variable names, how to do it?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-consisting-of-a-list-SAS-variable-names/m-p/131608#M26814</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When writing macros you should define the macro variables you create as local to prevent the use of them from accidentally changing the value of a macro variable that existed before the macro began execution. If you define a new macro variable with %LOCAL statement then it will be empty until you assign it a non empty value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can set a macro variable to empty using %LET. Example: %let varlist= ;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 08 Sep 2013 03:56:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-consisting-of-a-list-SAS-variable-names/m-p/131608#M26814</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-09-08T03:56:27Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro variable consisting of a list SAS variable names, how to do it?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-consisting-of-a-list-SAS-variable-names/m-p/131609#M26815</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How do you want to use the list?&lt;/P&gt;&lt;P&gt;If you want to define the variables in a data step then you really just need to know the upper bound, which you said was in the macro variable J.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; length amount1 - amount&amp;amp;j 8 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; ...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 08 Sep 2013 04:10:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-consisting-of-a-list-SAS-variable-names/m-p/131609#M26815</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-09-08T04:10:04Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro variable consisting of a list SAS variable names, how to do it?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-consisting-of-a-list-SAS-variable-names/m-p/131610#M26816</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would like to use the name list in a summary function in a proc sql such as&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select sum(0,&amp;amp;varlist) as amounts&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That is the reason I like comma as seperator.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 08 Sep 2013 05:56:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-variable-consisting-of-a-list-SAS-variable-names/m-p/131610#M26816</guid>
      <dc:creator>Macro</dc:creator>
      <dc:date>2013-09-08T05:56:14Z</dc:date>
    </item>
  </channel>
</rss>

