<?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 Macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/608654#M177168</link>
    <description>&lt;P&gt;&lt;BR /&gt;Hello&lt;/P&gt;
&lt;P&gt;I have the following challenge.&lt;/P&gt;
&lt;P&gt;There is a SAS program that depends on one user macro parameter (month).&lt;/P&gt;
&lt;P&gt;The user need to define month in %let statement.&lt;/P&gt;
&lt;P&gt;For example %let month=1904; (It means April 2019)&lt;/P&gt;
&lt;P&gt;IF we are in April 2019 then user need to run 4 times&amp;nbsp; (Because from January til April there are 4 runs&amp;nbsp; need to be done)&lt;/P&gt;
&lt;P&gt;%let month=1901;&lt;BR /&gt;%let month=1902;&lt;BR /&gt;&amp;nbsp;%let month=1903;&lt;/P&gt;
&lt;P&gt;%let month=1904;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know the way to change the program to macro.&lt;/P&gt;
&lt;P&gt;%macro RRR(month);&lt;/P&gt;
&lt;P&gt;....................................&lt;/P&gt;
&lt;P&gt;code&lt;/P&gt;
&lt;P&gt;%mend RRR;&lt;/P&gt;
&lt;P&gt;RRR(1904);&lt;/P&gt;
&lt;P&gt;RRR(1903);&lt;/P&gt;
&lt;P&gt;RRR(1902);&lt;/P&gt;
&lt;P&gt;RRR(1901);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;&lt;U&gt;My question:&lt;/U&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;How can I run the macros RRR automatically from&amp;nbsp; January this year till current month?&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;IF user run it in December 2019 then 12 macros will run automatically&lt;/P&gt;
&lt;P&gt;IF user run it in Novemeber 2019 then 11 macros will run automatically&lt;/P&gt;
&lt;P&gt;IF user run it in April&amp;nbsp; 2019 then 4 macros will run automatically&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The only argument that user define is current month (in format YYMM&amp;nbsp; for instance 1912)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 02 Dec 2019 10:15:14 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2019-12-02T10:15:14Z</dc:date>
    <item>
      <title>Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/608654#M177168</link>
      <description>&lt;P&gt;&lt;BR /&gt;Hello&lt;/P&gt;
&lt;P&gt;I have the following challenge.&lt;/P&gt;
&lt;P&gt;There is a SAS program that depends on one user macro parameter (month).&lt;/P&gt;
&lt;P&gt;The user need to define month in %let statement.&lt;/P&gt;
&lt;P&gt;For example %let month=1904; (It means April 2019)&lt;/P&gt;
&lt;P&gt;IF we are in April 2019 then user need to run 4 times&amp;nbsp; (Because from January til April there are 4 runs&amp;nbsp; need to be done)&lt;/P&gt;
&lt;P&gt;%let month=1901;&lt;BR /&gt;%let month=1902;&lt;BR /&gt;&amp;nbsp;%let month=1903;&lt;/P&gt;
&lt;P&gt;%let month=1904;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know the way to change the program to macro.&lt;/P&gt;
&lt;P&gt;%macro RRR(month);&lt;/P&gt;
&lt;P&gt;....................................&lt;/P&gt;
&lt;P&gt;code&lt;/P&gt;
&lt;P&gt;%mend RRR;&lt;/P&gt;
&lt;P&gt;RRR(1904);&lt;/P&gt;
&lt;P&gt;RRR(1903);&lt;/P&gt;
&lt;P&gt;RRR(1902);&lt;/P&gt;
&lt;P&gt;RRR(1901);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;&lt;U&gt;My question:&lt;/U&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;How can I run the macros RRR automatically from&amp;nbsp; January this year till current month?&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;IF user run it in December 2019 then 12 macros will run automatically&lt;/P&gt;
&lt;P&gt;IF user run it in Novemeber 2019 then 11 macros will run automatically&lt;/P&gt;
&lt;P&gt;IF user run it in April&amp;nbsp; 2019 then 4 macros will run automatically&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The only argument that user define is current month (in format YYMM&amp;nbsp; for instance 1912)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2019 10:15:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/608654#M177168</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-12-02T10:15:14Z</dc:date>
    </item>
    <item>
      <title>Re: Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/608657#M177169</link>
      <description>&lt;DIV&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;,&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;I believe you can create data-driven macro calls using the DOSUBL function as follows.&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;To use it, you need to have a dataset containing the different months values in the variable month.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input Month;
	cards;
1904
1905
1906
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set have;
rc=dosubl(cats('%RRR(',month,')'));
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Let me know!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2019 10:40:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/608657#M177169</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2019-12-02T10:40:53Z</dc:date>
    </item>
    <item>
      <title>Re: Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/608661#M177171</link>
      <description>&lt;P&gt;Use a wrapper macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro rrr(month);
%put &amp;amp;=month.;
%mend;

%macro run_all;
%local mm mo;
%do mm = 1 %to %sysfunc(month(%sysfunc(today())));
  %let mo=19%sysfunc(putn(&amp;amp;mm.,z2.));
  %rrr(&amp;amp;mo.)
%end;
%mend;
%run_all&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or call execute from a data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
do mm = 1 to month(today());
  call execute('%nrstr(%rrr(19'!!put(mm,z2.)!!'))');
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 02 Dec 2019 10:48:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/608661#M177171</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-12-02T10:48:52Z</dc:date>
    </item>
    <item>
      <title>Re: Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/608663#M177172</link>
      <description>&lt;P&gt;You can do the loop either by a data step or by a macro:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) using data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let month = 201904;

data _null:
    length month $6;
     month = symget("month");
     startm = input(substr(month,1 4)!!'01' , 6.);
     endm = input(month,6.);
     do mm from startm to endm;
          call execute("%rrr(" !! put(mm,6.) !! ");" );
     end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) using macro program:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let month = 201904;

%macro loop;
   %let yy = %substr(&amp;amp;month,1,4);
   %let mm1 =01;
   %let mme = %substr(&amp;amp;month,5,2);
   %do i=&amp;amp;mm1 %to &amp;amp;mme;&lt;BR /&gt;       %if %length(&amp;amp;i) = 1 %then %let i = 0&amp;amp;i;
       %rrr(&amp;amp;yy&amp;amp;i);
   %end;
%mend;
%loop;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 02 Dec 2019 10:53:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/608663#M177172</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2019-12-02T10:53:50Z</dc:date>
    </item>
  </channel>
</rss>

