<?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: Creating a variable list to loop through macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-list-to-loop-through-macro/m-p/437792#M109090</link>
    <description>&lt;P&gt;Thank you so much, this solution worked great. I did not know you could use the %sysfunc equation as part of a variable name, so I learned something new about DO loops and that as well.&lt;/P&gt;</description>
    <pubDate>Thu, 15 Feb 2018 21:26:59 GMT</pubDate>
    <dc:creator>jeattberg</dc:creator>
    <dc:date>2018-02-15T21:26:59Z</dc:date>
    <item>
      <title>Creating a variable list to loop through macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-list-to-loop-through-macro/m-p/437378#M108885</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to loop through the following code, for each month up to the current month. So if I ran this today, it would run for Jan (01) and Feb (02), and next month it will do the same, but also for Mar (03), and so on. I can't just do a do loop with I=1 to 12 because the DATE variable below is in the format of mm_2018_01. any suggestions?&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%MACRO&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; UPDATE_MM(MON=);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;create table tmp_&amp;amp;MON as&lt;/P&gt;&lt;P&gt;Select DISTINCT *&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;FROM WORK.SOURCE where DATE = &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"mm_&amp;amp;cu_yr._&amp;amp;mon"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%MEND&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; UPDATE_MM;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think I need to make a list of the month values, as shown below, and do a %do loop, but I'm not quite sure how.&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; MONTHS= O1 02 03 04 05 06 07 08 09 10 11 12;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%LET&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; TODAY=&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%SYSFUNC&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(TODAY(),DATE9.);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%LET&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; CU_MO= &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%Sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;( PutN("&amp;amp;TODAY"D, MONTH2 ) ) ;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 00:08:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-list-to-loop-through-macro/m-p/437378#M108885</guid>
      <dc:creator>jeattberg</dc:creator>
      <dc:date>2018-02-15T00:08:29Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a variable list to loop through macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-list-to-loop-through-macro/m-p/437383#M108888</link>
      <description>&lt;P&gt;Check the SAS 9.4 Macro appendix for an example of looping through dates in a macro loop.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 00:44:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-list-to-loop-through-macro/m-p/437383#M108888</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-15T00:44:01Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a variable list to loop through macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-list-to-loop-through-macro/m-p/437388#M108890</link>
      <description>&lt;P&gt;If you just want month looping, from one to the current month, maybe something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(dummy) ;
  %local month ;
  %do month=1 %to %sysfunc(today(),month) ;
    %put month: %sysfunc(putn(&amp;amp;month,z2)) ;
  %end ;
%mend test ;

%test()&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 01:04:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-list-to-loop-through-macro/m-p/437388#M108890</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2018-02-15T01:04:58Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a variable list to loop through macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-list-to-loop-through-macro/m-p/437403#M108899</link>
      <description>&lt;P&gt;I understand up to this point, I've found a couple ways to generate a list from 01 to current month, but how do I use that dynamic list to loop through my macro code. That's where I'm getting stuck. Thank you so much for your help!&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 02:40:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-list-to-loop-through-macro/m-p/437403#M108899</guid>
      <dc:creator>jeattberg</dc:creator>
      <dc:date>2018-02-15T02:40:54Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a variable list to loop through macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-list-to-loop-through-macro/m-p/437411#M108902</link>
      <description>&lt;P&gt;I think you are saying that you have a CHARACTER variable whose value starts with two digit month number?&lt;/P&gt;
&lt;P&gt;So the issue is getting those leading zeros.&lt;/P&gt;
&lt;P&gt;The Z. format can do that.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do month=1 to 12;
  %update_mm(mon=%sysfunc(putn(&amp;amp;month,z2)))
%end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Feb 2018 03:19:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-list-to-loop-through-macro/m-p/437411#M108902</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-02-15T03:19:11Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a variable list to loop through macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-list-to-loop-through-macro/m-p/437539#M108964</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO UPDATE_MM(MON=,CU_YR=);
	PROC SQL;
	create table tmp_&amp;amp;MON as
	Select DISTINCT *
	FROM WORK.SOURCE where DATE = "mm_&amp;amp;cu_yr._&amp;amp;mon" ;
	QUIT;
%MEND UPDATE_MM;

data _null_;
run_date=today();			/*Here you can put your date or programetically pass your date*/
cu_yr=put(year(run_date),z4.);
do i=1 to 12;
	mon=put(i,z2.);
	execution_cmd='%UPDATE_MM('||mon||','||cu_yr||')';
	call execute(execution_cmd);
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This will work, and it will be better if you pass the cu_yr macro variable to the macro function.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 12:33:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-list-to-loop-through-macro/m-p/437539#M108964</guid>
      <dc:creator>Satish_Parida</dc:creator>
      <dc:date>2018-02-15T12:33:22Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a variable list to loop through macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-list-to-loop-through-macro/m-p/437624#M109009</link>
      <description>&lt;P&gt;Assuming you have the macro variable CU_YR defined somewhere outside the macro (it is not created in the sample code you posted), I would think you could just paste your PROC SQL code into my %DO loop, so something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test ;
  %local month ;
  %do month=1 %to %sysfunc(today(),month) ;
    %put month: %sysfunc(putn(&amp;amp;month,z2)) ;
    
    PROC SQL;
      create table tmp_%sysfunc(putn(&amp;amp;month,z2)) as
      Select DISTINCT *
      FROM WORK.SOURCE where DATE = "mm_&amp;amp;cu_yr._%sysfunc(putn(&amp;amp;month,z2))" ;
    QUIT;

  %end ;
%mend test ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Feb 2018 15:15:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-list-to-loop-through-macro/m-p/437624#M109009</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2018-02-15T15:15:24Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a variable list to loop through macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-list-to-loop-through-macro/m-p/437792#M109090</link>
      <description>&lt;P&gt;Thank you so much, this solution worked great. I did not know you could use the %sysfunc equation as part of a variable name, so I learned something new about DO loops and that as well.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 21:26:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-list-to-loop-through-macro/m-p/437792#M109090</guid>
      <dc:creator>jeattberg</dc:creator>
      <dc:date>2018-02-15T21:26:59Z</dc:date>
    </item>
  </channel>
</rss>

