<?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: Repeated Macro Statements in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Repeated-Macro-Statements/m-p/641917#M191423</link>
    <description>&lt;P&gt;Thank you this was a great suggestion! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp; Appreciate all the help!&lt;/P&gt;</description>
    <pubDate>Wed, 22 Apr 2020 13:04:10 GMT</pubDate>
    <dc:creator>cjac45</dc:creator>
    <dc:date>2020-04-22T13:04:10Z</dc:date>
    <item>
      <title>Repeated Macro Statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repeated-Macro-Statements/m-p/641756#M191332</link>
      <description>&lt;P&gt;I have a program that I'm trying to build that will read in files for each month.&amp;nbsp; It will be a user needing to enter how many months were in and then letting it run.&amp;nbsp; For example the following.&amp;nbsp; If they ran it today they would only need to run the first 3, but I want it to be that they could just enter the number 3 and my program will run the first three repeat macros.&amp;nbsp; Does that make sense.&amp;nbsp; I then then those three datasets to set together.&amp;nbsp; So I would like to be able to enter 3 and it will run through this macro 3 times (March) and then set the 3 datasets together.&amp;nbsp; Next month I would come in and enter 4 and it would do the same thing.&amp;nbsp; Obviously this program is a lot more complex so this would help a ton.&amp;nbsp; Thanks a bunch.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro repeat (rpt_mnth, yr);&lt;BR /&gt;data SCCU_Member_data_&amp;amp;rpt_mnth._&amp;amp;rpt_yr.;&lt;BR /&gt;set in.SCCU_Member_data_&amp;amp;rpt_mnth._&amp;amp;rpt_yr.;&lt;BR /&gt;run;&lt;BR /&gt;data SNME_Member_data_&amp;amp;rpt_mnth._&amp;amp;rpt_yr.;&lt;BR /&gt;set in.SNME_Member_data_&amp;amp;rpt_mnth._&amp;amp;rpt_yr.;&lt;BR /&gt;run;&lt;BR /&gt;%mend repeat;&lt;BR /&gt;%repeat(1, 2020); /*January*/&lt;BR /&gt;%repeat(2, 2020); /*February*/&lt;BR /&gt;%repeat(3, 2020); /*March*/&lt;BR /&gt;%repeat(4, 2020); /*April*/&lt;BR /&gt;%repeat(5, 2020); /*May*/&lt;BR /&gt;%repeat(6, 2020); /*June*/&lt;BR /&gt;%repeat(7, 2020); /*July*/&lt;BR /&gt;%repeat(8, 2020); /*August*/&lt;BR /&gt;%repeat(9, 2020); /*September*/&lt;BR /&gt;%repeat(10, 2020); /*October*/&lt;BR /&gt;%repeat(11, 2020); /*November*/&lt;BR /&gt;%repeat(12, 2020); /*December*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data final_sccu_member;&lt;BR /&gt;set Sccu_member_data_1_2020 Sccu_member_data_2_2020 Sccu_member_data_3_2020;&lt;BR /&gt;run;&lt;BR /&gt;data final_snme_member;&lt;BR /&gt;set Snme_member_data_1_2020 Snme_member_data_2_2020 Snme_member_data_3_2020;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Apr 2020 21:32:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repeated-Macro-Statements/m-p/641756#M191332</guid>
      <dc:creator>cjac45</dc:creator>
      <dc:date>2020-04-21T21:32:47Z</dc:date>
    </item>
    <item>
      <title>Re: Repeated Macro Statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repeated-Macro-Statements/m-p/641758#M191333</link>
      <description>&lt;P&gt;Not sure if this is all you need:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro control(Maxmonth=, year=);
%local mi;
%do mi=1 %to &amp;amp;maxmonth.;
&amp;nbsp; &amp;nbsp; %repeat (&amp;amp;mi, &amp;amp;year.)
%end; /* of %di mi */

data final_sccu_member;
set 
%do mi=1 %to %do mi=1 %to &amp;amp;maxmonth.;
    Sccu_member_data_&amp;amp;mi._&amp;amp;year.
%end;&lt;BR /&gt;  ;
run;

data final_snme_member;
set
%do mi=1 %to %do mi=1 %to &amp;amp;maxmonth.;
    Snme_member_data_&amp;amp;mi._&amp;amp;year.
%end;&lt;BR /&gt;  ;
run;

%mend control;

/* call the control macro */
%control(maxmonth=3, year=2020);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Apr 2020 21:48:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repeated-Macro-Statements/m-p/641758#M191333</guid>
      <dc:creator>DavePrinsloo</dc:creator>
      <dc:date>2020-04-21T21:48:06Z</dc:date>
    </item>
    <item>
      <title>Re: Repeated Macro Statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repeated-Macro-Statements/m-p/641825#M191371</link>
      <description>&lt;P&gt;Try -- adjust macro to reflect your process. Requires no update in terms of dates since it is based on SYSDATE (today):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Macro;
%macro repeat(rpt_mnth,rpt_yr);
	data SCCU_Member_data_&amp;amp;rpt_mnth._&amp;amp;rpt_yr.;
		format message $50.;
		message=catx('','SCCU Data for Rpt_Month:',"&amp;amp;rpt_mnth",'Rpt_Year:',"&amp;amp;rpt_yr");
	run;
	data SNME_Member_data_&amp;amp;rpt_mnth._&amp;amp;rpt_yr.;
		format message $50.;
		message=catx('','SNME Data for Rpt_Month:',"&amp;amp;rpt_mnth",'Rpt_Year:',"&amp;amp;rpt_yr");
	run;
%mend;


*Run based on SYSDATE=TODAY;
%let mth=%sysfunc(month("&amp;amp;sysdate"d));
%let yr=%sysfunc(year("&amp;amp;sysdate"d));
%put &amp;amp;=mth &amp;amp;=yr;

data _null_;
	do i=1 to &amp;amp;mth-1;
		call execute(cats('%repeat(rpt_mnth=',i,',rpt_yr=',"&amp;amp;yr",')'));
	end;
run;

data final_sccu_member;
	set sccu_member_data_:;
run;

data final_snme_member;
	set snme_member_data_:;
run;

proc print data=final_sccu_member;
run;
proc print data=final_snme_member;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Apr 2020 06:58:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repeated-Macro-Statements/m-p/641825#M191371</guid>
      <dc:creator>unison</dc:creator>
      <dc:date>2020-04-22T06:58:46Z</dc:date>
    </item>
    <item>
      <title>Re: Repeated Macro Statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repeated-Macro-Statements/m-p/641833#M191376</link>
      <description>&lt;P&gt;Creating datasets for each month seems to be the first problem to be addressed. Having in.SCCU_Member_data with one date variable (formatted to display only month and year) would make all the joining redundant, same change for in.SNME_Member_data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you can't apply that bigger change, try&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;  
   months = intck('month', '01Jan2020'd, today());

   do i = 0 to months-1;
      date = intnx('month', '01Jan2020'd, i);
      call execute(cats('%nrstr(%repeat(', month(date), ',', year(date), '));'));
   end;
run;


data final_sccu_member;
   set Sccu_member_data_:;
run;
data final_snme_member;
   set Snme_member_data:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Apr 2020 07:54:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repeated-Macro-Statements/m-p/641833#M191376</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-04-22T07:54:20Z</dc:date>
    </item>
    <item>
      <title>Re: Repeated Macro Statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repeated-Macro-Statements/m-p/641849#M191388</link>
      <description>&lt;P&gt;If the data sets were named in YEAR_month order then, at least within a single year, this is much easier and no macro may be needed. You don't show any call for crossing a calendar year boundary so I'm not sure how valid that is&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regardless there is absolutely no need to copy the data set as you show unless you are doing other calculations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data junk_2020_1;
   set sashelp.class;
run;
data junk_2020_2;
   set sashelp.class;
run;
data junk_2020_3;
   set sashelp.class;
run;
data junk_2020_4;
   set sashelp.class;
run;
%let mnth=3;
data want;
   set junk_2020_1 - junk_2020_&amp;amp;mnth.
   ;
run;&lt;/PRE&gt;
&lt;P&gt;Which of course will fail if mnth references a data set that doesn't&amp;nbsp; yet exist.&lt;/P&gt;
&lt;P&gt;If you are doing calculations in each of those copied sets very likely you could move them to the step that combines the data.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Apr 2020 08:43:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repeated-Macro-Statements/m-p/641849#M191388</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-04-22T08:43:39Z</dc:date>
    </item>
    <item>
      <title>Re: Repeated Macro Statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repeated-Macro-Statements/m-p/641917#M191423</link>
      <description>&lt;P&gt;Thank you this was a great suggestion! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp; Appreciate all the help!&lt;/P&gt;</description>
      <pubDate>Wed, 22 Apr 2020 13:04:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repeated-Macro-Statements/m-p/641917#M191423</guid>
      <dc:creator>cjac45</dc:creator>
      <dc:date>2020-04-22T13:04:10Z</dc:date>
    </item>
  </channel>
</rss>

