<?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 Variable List in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-List/m-p/624192#M183833</link>
    <description>&lt;P&gt;You might want to refactor the way the code works to eliminate the need for this, but without details we cannot help with that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to get the variable names into a list.&amp;nbsp; (Note if they are literally VAR1 to VAR5000 then you can just generate them with a DO loop).&amp;nbsp; So use PROC CONTENTS or the dictionary view/tables.&amp;nbsp; Then use that data to generate the macro calls.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let ds=sashelp.class;
proc contents data=&amp;amp;ds out=contents noprint; run;

filename code temp;
data _null_;
  set contents;
  file code;
  put '%macro_run(' name ');' ;
run;
%include code / source2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Question: &lt;STRONG&gt;How do you know which 3 variables to exclude?&lt;/STRONG&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 12 Feb 2020 14:43:55 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-02-12T14:43:55Z</dc:date>
    <item>
      <title>Macro Variable List</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-List/m-p/624189#M183831</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset with 5003 variables. 5000 of these are required to call a macro (Var1 to Var5000).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How I can I avoid explicitly writing the lines below out every time?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro_run (Var1);&lt;/P&gt;&lt;P&gt;%macro_run (Var2);&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;%macro_run (Var5000);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Feb 2020 14:36:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-List/m-p/624189#M183831</guid>
      <dc:creator>PetePatel</dc:creator>
      <dc:date>2020-02-12T14:36:38Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable List</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-List/m-p/624191#M183832</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/154786"&gt;@PetePatel&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use the DOSUBL function (or CALL EXECUTE) to execute code immediately:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data list;
	do i=1 to 5000;
		var = cats('Var',i);
		output;
	end;
run;

data _null_;
	set list;
	rc = dosubl(cats('%macro_run (',Var,');'));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Feb 2020 14:40:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-List/m-p/624191#M183832</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-12T14:40:26Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable List</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-List/m-p/624192#M183833</link>
      <description>&lt;P&gt;You might want to refactor the way the code works to eliminate the need for this, but without details we cannot help with that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to get the variable names into a list.&amp;nbsp; (Note if they are literally VAR1 to VAR5000 then you can just generate them with a DO loop).&amp;nbsp; So use PROC CONTENTS or the dictionary view/tables.&amp;nbsp; Then use that data to generate the macro calls.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let ds=sashelp.class;
proc contents data=&amp;amp;ds out=contents noprint; run;

filename code temp;
data _null_;
  set contents;
  file code;
  put '%macro_run(' name ');' ;
run;
%include code / source2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Question: &lt;STRONG&gt;How do you know which 3 variables to exclude?&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Feb 2020 14:43:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-List/m-p/624192#M183833</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-12T14:43:55Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable List</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-List/m-p/624194#M183834</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can loop on the dataset columns names with "call vnext" and execute the macro with "call execute" as follows :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: added "stop;".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro mymacro(vname);

    %put Macro execution for variable &amp;amp;vname.;

%mend;

data have;
   input a b c d e f g h i j;
   cards;
1 2 3 4 5 6 7 8 9 0
;
run;

data _NULL_;
    set have;
    length _VNAME_ $32.;

    do while(_VNAME_ ne "_VNAME_");
        call vnext(_VNAME_);
        if _VNAME_ not in ("h" "i" "j" "_VNAME_") then 
            call execute(cats('%nrstr(%mymacro)(',_VNAME_,')'));
    end;

    stop;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Feb 2020 15:09:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-List/m-p/624194#M183834</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2020-02-12T15:09:09Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable List</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-List/m-p/624195#M183835</link>
      <description>&lt;P&gt;Thanks, Tom.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The variables are named differently but I know I need to exclude date time and month. The rest should be included.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So imagine if I have a dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Date&lt;/P&gt;&lt;P&gt;Time&lt;/P&gt;&lt;P&gt;Month&lt;/P&gt;&lt;P&gt;GRCV&lt;/P&gt;&lt;P&gt;GHPI_2&lt;/P&gt;&lt;P&gt;SIORP_0&lt;/P&gt;&lt;P&gt;RHP&lt;/P&gt;&lt;P&gt;TRYP&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I call the macro for the last 5 variables only.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently I am doing:&lt;/P&gt;&lt;P&gt;%Run_Macro (GRCV);&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;%Run_Macro (TRYP);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Feb 2020 14:59:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-List/m-p/624195#M183835</guid>
      <dc:creator>PetePatel</dc:creator>
      <dc:date>2020-02-12T14:59:44Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable List</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-List/m-p/624196#M183836</link>
      <description>&lt;P&gt;Depending on what %macro_run does, you may not need macros at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=abc;
    var var1-var5000;
    output out=_stats_ mean= std= /autoname;
run;
    &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Feb 2020 15:03:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-List/m-p/624196#M183836</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-02-12T15:03:23Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable List</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-List/m-p/624197#M183837</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc contents data=have out=want (keep=name where=(name not in ('Date', 'Time', 'Month'))) noprint;
run;

data _null_;
	set want;
	rc = dosubl(cats('%macro_run (',name,');'));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Feb 2020 15:04:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-List/m-p/624197#M183837</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-12T15:04:05Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable List</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-List/m-p/624200#M183839</link>
      <description>where upcase(name) not in ('DATE' 'TIME' 'MONTH');&lt;BR /&gt;</description>
      <pubDate>Wed, 12 Feb 2020 15:06:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-List/m-p/624200#M183839</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-12T15:06:00Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable List</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-List/m-p/624204#M183842</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/154786"&gt;@PetePatel&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks, Tom.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The variables are named differently but I know I need to exclude date time and month. The rest should be included.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So imagine if I have a dataset:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Date&lt;/P&gt;
&lt;P&gt;Time&lt;/P&gt;
&lt;P&gt;Month&lt;/P&gt;
&lt;P&gt;GRCV&lt;/P&gt;
&lt;P&gt;GHPI_2&lt;/P&gt;
&lt;P&gt;SIORP_0&lt;/P&gt;
&lt;P&gt;RHP&lt;/P&gt;
&lt;P&gt;TRYP&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I call the macro for the last 5 variables only.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Currently I am doing:&lt;/P&gt;
&lt;P&gt;%Run_Macro (GRCV);&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;%Run_Macro (TRYP);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Again, depending on what %Run_Macro does, you may not need macros at all&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=have out=_contents_ noprint;
run;
proc sql noprint;
    select distinct name into :names separated by ' ' from _contents_
        where upcase(name) not in ('DATE','TIME','MONTH');
quit;
proc summary data=have;
    var &amp;amp;names;
    output out=stats mean= std=/autoname;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Feb 2020 15:13:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-List/m-p/624204#M183842</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-02-12T15:13:21Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable List</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-List/m-p/624206#M183844</link>
      <description>&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 12 Feb 2020 15:17:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-List/m-p/624206#M183844</guid>
      <dc:creator>PetePatel</dc:creator>
      <dc:date>2020-02-12T15:17:17Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable List</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-List/m-p/624217#M183851</link>
      <description>&lt;P&gt;Here is one approach to retrieve the last five variables of your dataset:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=have out=want (keep=name varnum where=(name not in ('Date', 'Time', 'Month'))) noprint;
run;

data list;
	if _n_=1 then do;
		declare hash h (dataset:'want', ordered:'d');
		h.definekey('VARNUM');
		h.definedata('VARNUM','NAME');
		h.definedone();
		declare hiter C('h');
	end;
	set want;
	C.first();
	output;
	do i=1 to 4;
		C.next();
		output;
	end;
	stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Feb 2020 15:49:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-List/m-p/624217#M183851</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-12T15:49:15Z</dc:date>
    </item>
  </channel>
</rss>

