<?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: List of variables in a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/List-of-variables-in-a-macro/m-p/783111#M249667</link>
    <description>I am sorry if I am not clear enough.&lt;BR /&gt;&lt;BR /&gt;The macrovariables doesn't get created. The log doesn't contain these five macrovariables in the list when I run the %put _user_</description>
    <pubDate>Tue, 30 Nov 2021 12:28:49 GMT</pubDate>
    <dc:creator>NinnaLinde</dc:creator>
    <dc:date>2021-11-30T12:28:49Z</dc:date>
    <item>
      <title>List of variables in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-of-variables-in-a-macro/m-p/783107#M249665</link>
      <description>&lt;P&gt;Hello everyone&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to make 5 macro variables that contain a list of variables. It doesn't seem to work for me, and I cant figure out why.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%let fil = var1;
%let tal = 1;

proc contents data= svar out=varliste varnum;
run;

data var1 var2 var3 var4 var5 ;
set varliste(keep=name varnum);
if varnum in (120, 127:277) then output var1;
if varnum in (121, 278:428) then output var2;
if varnum in (122, 429:579) then output var3;
if varnum in (123, 580:730) then output var4;
if varnum in (124, 731:881) then output var5;
run;
 
%macro varliste (tal, fil);
proc sql;
select name into :varliste&amp;amp;tal.
from &amp;amp;fil;
run;
%mend varliste;
%varliste (1, var1);
%varliste (2, var2);
%varliste (3, var3);
%varliste (4, var4);
%varliste (5, var5);
%put _user_;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I hope someone can help me!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ninna&lt;/P&gt;</description>
      <pubDate>Tue, 30 Nov 2021 12:18:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-of-variables-in-a-macro/m-p/783107#M249665</guid>
      <dc:creator>NinnaLinde</dc:creator>
      <dc:date>2021-11-30T12:18:32Z</dc:date>
    </item>
    <item>
      <title>Re: List of variables in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-of-variables-in-a-macro/m-p/783110#M249666</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/408316"&gt;@NinnaLinde&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello everyone&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to make 5 macro variables that contain a list of variables. It doesn't seem to work for me, and I cant figure out why.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;We don't know what this means. You haven't told us what is wrong, and what should happen that would fix it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm going to take a guess that you need a %GLOBAL statement inside your macro named %VARLISTE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%global varliste&amp;amp;tal;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If that doesn't fix the problem, then explain the problem, and explain what would be the desired result.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And in the future, please explain what is wrong and the desired result. Don't just show us code and say it isn't working.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Nov 2021 12:29:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-of-variables-in-a-macro/m-p/783110#M249666</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-11-30T12:29:36Z</dc:date>
    </item>
    <item>
      <title>Re: List of variables in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-of-variables-in-a-macro/m-p/783111#M249667</link>
      <description>I am sorry if I am not clear enough.&lt;BR /&gt;&lt;BR /&gt;The macrovariables doesn't get created. The log doesn't contain these five macrovariables in the list when I run the %put _user_</description>
      <pubDate>Tue, 30 Nov 2021 12:28:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-of-variables-in-a-macro/m-p/783111#M249667</guid>
      <dc:creator>NinnaLinde</dc:creator>
      <dc:date>2021-11-30T12:28:49Z</dc:date>
    </item>
    <item>
      <title>Re: List of variables in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-of-variables-in-a-macro/m-p/783115#M249669</link>
      <description>&lt;P&gt;Macro variables created in a macro will be local to that macro, unless they already exist in the global symbol table.&lt;/P&gt;
&lt;P&gt;Add a %GLOBAL statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro varliste (tal, fil);
%global varliste&amp;amp;tal;
proc sql;
select name into :varliste&amp;amp;tal.
from &amp;amp;fil;
quit;
%mend varliste;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also note that PROC SQL is terminated by a QUIT and not a RUN statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you want to create a list of names in each macro variable, you need to tell SQL that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro varliste (tal, fil);
%global varliste&amp;amp;tal;
proc sql;
select name into :varliste&amp;amp;tal. separated by " "
from &amp;amp;fil;
quit;
%mend varliste;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to use the list in SQL, change the separator to a comma.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Nov 2021 12:44:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-of-variables-in-a-macro/m-p/783115#M249669</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-11-30T12:44:26Z</dc:date>
    </item>
    <item>
      <title>Re: List of variables in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-of-variables-in-a-macro/m-p/783116#M249670</link>
      <description>&lt;P&gt;And, seeing that you have ~1000 variables in your initial dataset, I question that design. Data is usually easier to deal with in a long layout, so you should look at this aspect of your task.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Nov 2021 12:48:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-of-variables-in-a-macro/m-p/783116#M249670</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-11-30T12:48:33Z</dc:date>
    </item>
    <item>
      <title>Re: List of variables in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-of-variables-in-a-macro/m-p/783119#M249673</link>
      <description>Thank you very much for your time!</description>
      <pubDate>Tue, 30 Nov 2021 12:53:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-of-variables-in-a-macro/m-p/783119#M249673</guid>
      <dc:creator>NinnaLinde</dc:creator>
      <dc:date>2021-11-30T12:53:09Z</dc:date>
    </item>
  </channel>
</rss>

