<?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: CAN I EXECUTE LOOPS ON ENCAPSULATED MACROS? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/CAN-I-EXECUTE-LOOPS-ON-ENCAPSULATED-MACROS/m-p/897666#M354756</link>
    <description>&lt;P&gt;I think you are looking for an quick way for macro loops, which may like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do i=1 %to 12;
  %EXTRACT(_2017%sysfunc(putn(&amp;amp;i.,z2.)),FIRST_2017,&amp;amp;i.);
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I would like to recommand you &lt;A href="https://www.lexjansen.com/wuss/2008/app/app04.pdf" target="_self"&gt;the %for macro&amp;nbsp;&lt;/A&gt;version:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%for(i,in=1:12,do=%nrstr(
  %EXTRACT(_2017%sysfunc(putn(&amp;amp;i.,z2.)),FIRST_2017,&amp;amp;i.);
));&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 07 Oct 2023 09:55:35 GMT</pubDate>
    <dc:creator>whymath</dc:creator>
    <dc:date>2023-10-07T09:55:35Z</dc:date>
    <item>
      <title>CAN I EXECUTE LOOPS ON ENCAPSULATED MACROS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CAN-I-EXECUTE-LOOPS-ON-ENCAPSULATED-MACROS/m-p/897658#M354743</link>
      <description>&lt;P&gt;Encapsulated macros can only perform one operation, each time I need a piece of code, sometimes I want to use a macro code to perform multiple loop operations, is this OK? Or is there another solution?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO EXTRACT(DATANAME,IMPORTNAME,MONTH);
DATA &amp;amp;DATANAME ;
SET &amp;amp;IMPORTNAME;
WHERE MONTH(VAR2)=&amp;amp;MONTH;
SUM+VAR3;
MEAN=SUM/_N_;
KEEP VAR2 VAR3 SUM MEAN;
RUN;
%MEND EXTRACT;
%LET JAN=1;
%LET FEB=2;
%LET MAR=3;
%LET APR=4;
%LET MAY=5;
%LET JUN=6;
%LET JUL=7;
%LET AUG=8;
%LET SEP=9;
%LET OCT=10;
%LET NOV=11;
%LET DEC=12;
%EXTRACT(_201701,FIRST_2017,&amp;amp;JAN);
%EXTRACT(_201702,FIRST_2017,&amp;amp;FEB);
%EXTRACT(_201703,FIRST_2017,&amp;amp;MAR);
%EXTRACT(_201704,FIRST_2017,&amp;amp;APR);
%EXTRACT(_201705,FIRST_2017,&amp;amp;MAY);
%EXTRACT(_201706,FIRST_2017,&amp;amp;JUN);
%EXTRACT(_201707,FIRST_2017,&amp;amp;JUL);
%EXTRACT(_201708,FIRST_2017,&amp;amp;AUG);
%EXTRACT(_201709,FIRST_2017,&amp;amp;SEP);
%EXTRACT(_201710,FIRST_2017,&amp;amp;OCT);
%EXTRACT(_201711,FIRST_2017,&amp;amp;NOV);
%EXTRACT(_201712,FIRST_2017,&amp;amp;DEC);
..........
%EXTRACT(_201901,FIRST_2019,&amp;amp;JAN);
/*This seems too verbose, so what are some ways to make your code more concise*/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":thinking_face:"&gt;🤔&lt;/span&gt;&lt;span class="lia-unicode-emoji" title=":thinking_face:"&gt;🤔&lt;/span&gt;&lt;span class="lia-unicode-emoji" title=":thinking_face:"&gt;🤔&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 07 Oct 2023 03:39:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CAN-I-EXECUTE-LOOPS-ON-ENCAPSULATED-MACROS/m-p/897658#M354743</guid>
      <dc:creator>_Sas_Beginner_</dc:creator>
      <dc:date>2023-10-07T03:39:17Z</dc:date>
    </item>
    <item>
      <title>Re: CAN I EXECUTE LOOPS ON ENCAPSULATED MACROS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CAN-I-EXECUTE-LOOPS-ON-ENCAPSULATED-MACROS/m-p/897660#M354745</link>
      <description>&lt;P&gt;CALL EXECUTE() allows you to generate macro calls that get stacked and then all executed once the data step terminates.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  do dt='01jan2017'd to '01dec2020'd;
    cmd=cats('%EXTRACT(_',put(dt,yymmn6.),',first_',put(dt,year4.),',', month(dt),  ');' );
    put cmd=;
/*    call execute( cmd );*/
    dt=intnx('month',dt,0,'e');
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 07 Oct 2023 04:24:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CAN-I-EXECUTE-LOOPS-ON-ENCAPSULATED-MACROS/m-p/897660#M354745</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-10-07T04:24:05Z</dc:date>
    </item>
    <item>
      <title>Re: CAN I EXECUTE LOOPS ON ENCAPSULATED MACROS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CAN-I-EXECUTE-LOOPS-ON-ENCAPSULATED-MACROS/m-p/897661#M354746</link>
      <description>&lt;P&gt;How about don't bother to create all those data sets. Use a WHERE clause the full data set if you really need to subset the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Proc print data=first_2017 (where=(month(var2)=1));
run;&lt;/PRE&gt;
&lt;P&gt;Or if you must perhaps a driver macro&lt;/P&gt;
&lt;PRE&gt;%macro driver(dsn, datastem);
%do i = 1 %to 12;
   %let name=&amp;amp;datastem.%sysfunc(putn(&amp;amp;i.,z2.));
   %extract(&amp;amp;name, &amp;amp;dsn,&amp;amp;i);
%end;
%mend;&lt;/PRE&gt;
&lt;P&gt;DSN would be the name of the source data set, datastem would be the desired output name without the 01, 02, etc. Name builds the desiret output name and the loop counter provides the number of the month.&lt;/P&gt;</description>
      <pubDate>Sat, 07 Oct 2023 05:02:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CAN-I-EXECUTE-LOOPS-ON-ENCAPSULATED-MACROS/m-p/897661#M354746</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-10-07T05:02:26Z</dc:date>
    </item>
    <item>
      <title>Re: CAN I EXECUTE LOOPS ON ENCAPSULATED MACROS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CAN-I-EXECUTE-LOOPS-ON-ENCAPSULATED-MACROS/m-p/897666#M354756</link>
      <description>&lt;P&gt;I think you are looking for an quick way for macro loops, which may like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do i=1 %to 12;
  %EXTRACT(_2017%sysfunc(putn(&amp;amp;i.,z2.)),FIRST_2017,&amp;amp;i.);
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I would like to recommand you &lt;A href="https://www.lexjansen.com/wuss/2008/app/app04.pdf" target="_self"&gt;the %for macro&amp;nbsp;&lt;/A&gt;version:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%for(i,in=1:12,do=%nrstr(
  %EXTRACT(_2017%sysfunc(putn(&amp;amp;i.,z2.)),FIRST_2017,&amp;amp;i.);
));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 07 Oct 2023 09:55:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CAN-I-EXECUTE-LOOPS-ON-ENCAPSULATED-MACROS/m-p/897666#M354756</guid>
      <dc:creator>whymath</dc:creator>
      <dc:date>2023-10-07T09:55:35Z</dc:date>
    </item>
    <item>
      <title>Re: CAN I EXECUTE LOOPS ON ENCAPSULATED MACROS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CAN-I-EXECUTE-LOOPS-ON-ENCAPSULATED-MACROS/m-p/897667#M354757</link>
      <description>thank you for ur answer,i have tried to run ur code ,it is work!mainly focused on"turn code into characters and store it in variables to run",i think it is very technical.&lt;BR /&gt;thank u for letting me learn new knowledge!</description>
      <pubDate>Sat, 07 Oct 2023 12:37:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CAN-I-EXECUTE-LOOPS-ON-ENCAPSULATED-MACROS/m-p/897667#M354757</guid>
      <dc:creator>_Sas_Beginner_</dc:creator>
      <dc:date>2023-10-07T12:37:25Z</dc:date>
    </item>
    <item>
      <title>Re: CAN I EXECUTE LOOPS ON ENCAPSULATED MACROS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CAN-I-EXECUTE-LOOPS-ON-ENCAPSULATED-MACROS/m-p/897668#M354758</link>
      <description>thank u for ur answer, i have tried to run ur code , mainly focusing on"calling another macro in one macro", this method is very flexible and useful to use, thank u for letting me learn new knowledge!</description>
      <pubDate>Sat, 07 Oct 2023 12:44:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CAN-I-EXECUTE-LOOPS-ON-ENCAPSULATED-MACROS/m-p/897668#M354758</guid>
      <dc:creator>_Sas_Beginner_</dc:creator>
      <dc:date>2023-10-07T12:44:04Z</dc:date>
    </item>
    <item>
      <title>Re: CAN I EXECUTE LOOPS ON ENCAPSULATED MACROS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CAN-I-EXECUTE-LOOPS-ON-ENCAPSULATED-MACROS/m-p/897669#M354759</link>
      <description>I have tried to run the second method you recommend and I am a bit confused about what %for means, prompting that it is a macro that needs to be customized and it doesn't seem to work correctly, but I appreciate your answer anyway</description>
      <pubDate>Sat, 07 Oct 2023 13:04:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CAN-I-EXECUTE-LOOPS-ON-ENCAPSULATED-MACROS/m-p/897669#M354759</guid>
      <dc:creator>_Sas_Beginner_</dc:creator>
      <dc:date>2023-10-07T13:04:46Z</dc:date>
    </item>
    <item>
      <title>Re: CAN I EXECUTE LOOPS ON ENCAPSULATED MACROS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CAN-I-EXECUTE-LOOPS-ON-ENCAPSULATED-MACROS/m-p/897670#M354760</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/434736"&gt;@_Sas_Beginner_&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm approaching this from these perspectives&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Using named macro parameters rather than positional&lt;/LI&gt;
&lt;LI&gt;Reding the source data set only once, while producing multiple output data sets&lt;/LI&gt;
&lt;LI&gt;Providing the flexibility to explicitly pick your min-max months&lt;/LI&gt;
&lt;/UL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO EXTRACT(p_inDsName=, p_year=, p_minMonth=1, p_maxMonth=12);
	%LOCAL l_i;

	DATA
		/* Dynamically construct the output data set names */
		%do l_i=&amp;amp;p_minMonth %to &amp;amp;p_maxMonth; _&amp;amp;p_year.%sysfunc(putn(&amp;amp;l_i,z2.)) %end;
	;

		/* Using DOW Loop for selective iterative processing */
		DO _n_=1 by 1 UNTIL (last.VAR2);
		
			/* Filter the data by specified year */
			SET &amp;amp;p_inDsName(where=(year=&amp;amp;p_year));
			BY VAR2;
			
			SUM+VAR3;
			MEAN=SUM/_N_;
			
			/* Dynamically construct the output statements */
			%let l_i=&amp;amp;p_minMonth;
			if (put(MONTH,month.)=&amp;amp;l_i) then output _&amp;amp;p_year.%sysfunc(putn(&amp;amp;l_i,z2.));
			%do l_i=%eval(&amp;amp;p_minMonth+1) %to &amp;amp;p_maxMonth;
				else if (put(MONTH,month.)=&amp;amp;l_i) then output _&amp;amp;p_year.%sysfunc(putn(&amp;amp;l_i,z2.));
			%end;
		END;

		KEEP VAR2 VAR3 SUM MEAN; 
	RUN;

%MEND EXTRACT;

options mprint; /* Display in the log the SAS statements being processed */
&lt;BR /&gt;/* Ensure data set properly sorted */
%let g_srcDsName= first_2017;&lt;BR /&gt;proc sort data=&amp;amp;g_srcDsName;
	by var2 year;
run;
%EXTRACT(p_inDsName=&amp;amp;g_srcDsName, p_year=2017, p_minMonth=1, p_maxMonth=12);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;Ahmed&lt;/P&gt;</description>
      <pubDate>Sat, 07 Oct 2023 13:22:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CAN-I-EXECUTE-LOOPS-ON-ENCAPSULATED-MACROS/m-p/897670#M354760</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2023-10-07T13:22:44Z</dc:date>
    </item>
    <item>
      <title>Re: CAN I EXECUTE LOOPS ON ENCAPSULATED MACROS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CAN-I-EXECUTE-LOOPS-ON-ENCAPSULATED-MACROS/m-p/897674#M354763</link>
      <description>&lt;P&gt;I don't understand what you are doing and why you need any macro code at all.&lt;/P&gt;
&lt;P&gt;You appear to be calculating a cumulative SUM and MEAN of some VALUE by MONTH.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  by MONTH ;
  if first.month then call missing(n,sum);
  n+1;
  sum+VALUE ;
  mean=sum/n;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;In your case you have named the MONTH variable as VAR2 and the VALUE variable as VAR3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And if you don't need all of the intermediate sums and means then you can just use PROC SUMMARY (aka PROC MEANS) to find the SUM and MEAN per month.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have nway;
  by month;
  var VALUE;
  output out=want sum=sum mean=mean n=n ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And if the data is not already sorted by MONTH you can use CLASS MONTH instead of BY MONTH.&lt;/P&gt;</description>
      <pubDate>Sat, 07 Oct 2023 15:43:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CAN-I-EXECUTE-LOOPS-ON-ENCAPSULATED-MACROS/m-p/897674#M354763</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-10-07T15:43:02Z</dc:date>
    </item>
    <item>
      <title>Re: CAN I EXECUTE LOOPS ON ENCAPSULATED MACROS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CAN-I-EXECUTE-LOOPS-ON-ENCAPSULATED-MACROS/m-p/897675#M354764</link>
      <description>Thank you very much for your reply. Yes, I have 12 data sets, each of which has more than 60,000 data, but the date of the data is taken as a data row in the form of every day, similar to "2017Jan01 2017Jan02", but I want to calculate its average value in monthly time, and the by statement is invalid</description>
      <pubDate>Sat, 07 Oct 2023 15:50:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CAN-I-EXECUTE-LOOPS-ON-ENCAPSULATED-MACROS/m-p/897675#M354764</guid>
      <dc:creator>_Sas_Beginner_</dc:creator>
      <dc:date>2023-10-07T15:50:13Z</dc:date>
    </item>
    <item>
      <title>Re: CAN I EXECUTE LOOPS ON ENCAPSULATED MACROS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CAN-I-EXECUTE-LOOPS-ON-ENCAPSULATED-MACROS/m-p/897679#M354766</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/434736"&gt;@_Sas_Beginner_&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you very much for your reply. Yes, I have 12 data sets, each of which has more than 60,000 data, but the date of the data is taken as a data row in the form of every day, similar to "2017Jan01 2017Jan02", but I want to calculate its average value in monthly time, and the by statement is invalid&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That does not help much.&amp;nbsp; Does the variable actual contain date values (numeric variable with a display format like DATE9 or YYMMDD10 that will display the dates in a human recognizable way)?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;Or is the variable a character string?&amp;nbsp; If so are the values consistent?&amp;nbsp; So values for the month of January in the year 2017 always start with the string '2017Jan' and never have '2017JAN' or '2017 Jan' or '2017-Jan' instead?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Either way CLASS will work.&amp;nbsp; You just need to make to use a FORMAT that maps the values for the same month to the same string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do the dataset have the YEAR as the last 4 characters of the dataset name?&amp;nbsp; Then it should be simple to combine them.&amp;nbsp; You can use a data step VIEW to combine them on-the-fly so you don't have to save the combined values back to an actual dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So for example to produce monthly SUM and MEAN for the variable VALUE of the data for the years 2017 thru 2020 you could use these two steps.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data all_years / view=all_years;
  set  FIRST_2017-FIRST_2020 ;
* For Numeric DATE variable ;
  month = put(date,yymm7.);
/*
* For Character DATE variable ;
  month = substr(date,1,7);
*/
run;
proc summary data=all_years nway;
  class month;
  var VALUE ;
  output out=WANT sum= mean= n= / autoname ;
run;&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>Sat, 07 Oct 2023 17:59:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CAN-I-EXECUTE-LOOPS-ON-ENCAPSULATED-MACROS/m-p/897679#M354766</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-10-07T17:59:25Z</dc:date>
    </item>
    <item>
      <title>Re: CAN I EXECUTE LOOPS ON ENCAPSULATED MACROS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CAN-I-EXECUTE-LOOPS-ON-ENCAPSULATED-MACROS/m-p/897699#M354775</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data all_years ;
  set  FIRST_2017-FIRST_2023 SECOND_2017-SECOND_2022 ;
MONTH=MONTH(VAR2);
  YEAR=YEAR(VAR2);
run;
proc summary data=all_years nway;
  class MONTH YEAR ;
  var VAR3 ;
  output out=WANT sum= mean= n= / autoname ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hello, I modified the code you provided, it is undoubtedly successful, and completely achieved my purpose, indeed this does not require any macro language, and it seems simpler, in fact, I am more concerned with the question: can the macro implement a loop in the process of calling, so that I can write more efficient code in the face of other similar situations, of course, other people's replies have benefited me a lot, I am very grateful to you&lt;span class="lia-unicode-emoji" title=":hugging_face:"&gt;🤗&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Oct 2023 01:58:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CAN-I-EXECUTE-LOOPS-ON-ENCAPSULATED-MACROS/m-p/897699#M354775</guid>
      <dc:creator>_Sas_Beginner_</dc:creator>
      <dc:date>2023-10-08T01:58:35Z</dc:date>
    </item>
    <item>
      <title>Re: CAN I EXECUTE LOOPS ON ENCAPSULATED MACROS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CAN-I-EXECUTE-LOOPS-ON-ENCAPSULATED-MACROS/m-p/897700#M354776</link>
      <description>&lt;P&gt;If you want to loop over date and/or time intervals then use an OFFSET variable and the INTNX() and INTCK() functions with the appropriate interval name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In SAS code that might look like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do offset=0 to intck('month',start,end);
   date = intnx('month',start,offset);
....
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In MACRO code you will need to wrap the function calls in %SYSFUNC().&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do offset=0 %to %sysfunc(intck(month,&amp;amp;start,&amp;amp;end));
   %let date = %sysfunc(intnx(month,&amp;amp;start,&amp;amp;offset));
....
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note the offset and INTNX() is not needed when the intervals are just multiples of the units used to store the values.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example to loop by days just use a normal DO loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do date=start to end ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or to loop by hours just use a time constant for the step value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do time = start_time to end_time by '01:00:00't ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Oct 2023 02:54:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CAN-I-EXECUTE-LOOPS-ON-ENCAPSULATED-MACROS/m-p/897700#M354776</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-10-08T02:54:26Z</dc:date>
    </item>
  </channel>
</rss>

