<?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: Run macro for each argument from vector in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Run-macro-for-each-argument-from-vector/m-p/670060#M201095</link>
    <description>&lt;P&gt;You can code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let vector = 2001 2004 2005 2006;
%macro run_all;
    %let n = %sysfunc(countw("&amp;amp;vector")); /* argument can be either quoted or not */
    %do i=1 %to &amp;amp;n;
          %let mm = %scan(&amp;amp;vector,&amp;amp;i);
          %RRR(&amp;amp;mm);
    %end;
%mend run_all;
%run_all;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 17 Jul 2020 08:14:49 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2020-07-17T08:14:49Z</dc:date>
    <item>
      <title>Run macro for each argument from vector</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-macro-for-each-argument-from-vector/m-p/670054#M201092</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;There is a process that perform summary statistics from multiple data sets.&lt;/P&gt;
&lt;P&gt;Each data set contain the name with YYMM format.&lt;/P&gt;
&lt;P&gt;for example:&lt;/P&gt;
&lt;P&gt;t2001 includes data for JAN 2020&lt;/P&gt;
&lt;P&gt;t2004 includes data for APR 2020&lt;/P&gt;
&lt;P&gt;and so on&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know how to run the macro manually for each month that I need.&lt;/P&gt;
&lt;P&gt;If the name of the macro is RRR and I want to run for periods 2001 2004 2005 2006&amp;nbsp; then&amp;nbsp; I need to run the statements:&lt;/P&gt;
&lt;P&gt;%RRR(2001);&lt;/P&gt;
&lt;P&gt;%RRR(2004);&lt;/P&gt;
&lt;P&gt;%RRR(2005);&lt;/P&gt;
&lt;P&gt;%RRR(2006);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My question is what is the way to define one macro parameter with %let that includes the periods that I want to run for them the macro and then to run the macro for each of the arguments in the macro parameter&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;%let vector=2001+2004+2005+2006;
%let k=4;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data t2001;
input id y;
1 10
2 20
;
Run;

data t2004;
input id y;
1 11
2 21
;
Run;

data t2005;
input id y;
1 15
2 25
;
Run;

data t2006;
input id y;
1 18
2 27
;
Run;

%macro RRR;
create table summary&amp;amp;YYMM.  as
select sum(Y) as  sum_Y_&amp;amp;YYMM.
from  t&amp;amp;YYMM.
;
quit;
%mend RRR;

/*Way1 to run the macros*/
%RRR(2001);
%RRR(2004);
%RRR(2005);
%RRR(2006);

/*Way2 to run the macros*/
%let vector=2001+2004+2005+2006;
%let k=4;
Now need to run automatically for each argument in vector macro parameter
What is the way to do it please?&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Jul 2020 04:52:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-macro-for-each-argument-from-vector/m-p/670054#M201092</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-07-17T04:52:01Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro for each argument from vector</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-macro-for-each-argument-from-vector/m-p/670058#M201094</link>
      <description>&lt;P&gt;Loop over &amp;amp;vector, extract each year with scan-function, call macro rrr for each extracted value. I am 100% sure, that this has been asked and answered already, e.g. &lt;A href="https://communities.sas.com/t5/SAS-Programming/conditionally-import-no-output/m-p/614550" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/conditionally-import-no-output/m-p/614550&lt;/A&gt; - wait that was a question asked by yourself.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jul 2020 05:27:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-macro-for-each-argument-from-vector/m-p/670058#M201094</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-07-17T05:27:55Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro for each argument from vector</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-macro-for-each-argument-from-vector/m-p/670060#M201095</link>
      <description>&lt;P&gt;You can code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let vector = 2001 2004 2005 2006;
%macro run_all;
    %let n = %sysfunc(countw("&amp;amp;vector")); /* argument can be either quoted or not */
    %do i=1 %to &amp;amp;n;
          %let mm = %scan(&amp;amp;vector,&amp;amp;i);
          %RRR(&amp;amp;mm);
    %end;
%mend run_all;
%run_all;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jul 2020 08:14:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-macro-for-each-argument-from-vector/m-p/670060#M201095</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-07-17T08:14:49Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro for each argument from vector</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-macro-for-each-argument-from-vector/m-p/670065#M201099</link>
      <description>&lt;P&gt;Great,&lt;/P&gt;
&lt;P&gt;so as I understand in this case need to define 2 macros.&lt;/P&gt;
&lt;P&gt;first Macro to perform the summary statistics from source data sets&lt;/P&gt;
&lt;P&gt;Second Macro to Run the first macro on the relevant data sets&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro RRR;							
create table summary&amp;amp;YYMM.  as							
select sum(Y) as  sum_Y_&amp;amp;YYMM.							
from  t&amp;amp;YYMM.							
;							
quit;							
%mend RRR;							
							
%let vector=2001+2004+2005+2006;							
%let k = %sysfunc(countw(&amp;amp;vector));							
%macro RUN_RRR; 							
%do j=1 %to &amp;amp;k.;							
%let YYMM=%scan(&amp;amp;vector.,&amp;amp;j.,+);							
%RRR(&amp;amp;YYMM.);							
%end;							
%mend RUN_RRR;							
%RUN_RRR;							
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Jul 2020 06:01:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-macro-for-each-argument-from-vector/m-p/670065#M201099</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-07-17T06:01:02Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro for each argument from vector</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-macro-for-each-argument-from-vector/m-p/670066#M201100</link>
      <description>&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jul 2020 06:01:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-macro-for-each-argument-from-vector/m-p/670066#M201100</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-07-17T06:01:25Z</dc:date>
    </item>
  </channel>
</rss>

