<?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 How to make a macro to loop through two non consecutive months? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-macro-to-loop-through-two-non-consecutive-months/m-p/753426#M237453</link>
    <description>&lt;P&gt;I am doing an analysis on data for 3 specific months: 202006, 202007, 202008.&lt;/P&gt;
&lt;P&gt;And for each of these 3 months, I want a macro loop, which will run only for M-1 and M+6 month where M takes the above three months as values. The starting part of my macro is this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET Mon_ST = 202006;			
%LET Mon_EN = 202008;			
Option obs = Max;			
			
%macro copy_data();			
			
%DO Mnth = &amp;amp;Mon_ST. %TO &amp;amp;Mon_EN. ;			
%IF %SUBSTR(&amp;amp;Mnth.,5,2) = 13 %THEN %LET Mnth =	%EVAL(%SUBSTR(&amp;amp;Mnth.,1,4)+1)01;	
%Put Mnth = &amp;amp;Mnth.;	&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now, I want to create another loop within this macro which will run for only two specific time periods for each of these months. For eaxample, when Mnth =202006, the loop will create another macro variable, say MON, which will first take value 202005 (Mnth-1) and on the next iteration will take value 202012 (Mnth+6). Similary,&amp;nbsp;when Mnth =202007, MON will first be equal to 202006, and then 202101.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do I create this sub loop? Any help will be much appreciated. Thanks!&lt;/P&gt;</description>
    <pubDate>Mon, 12 Jul 2021 06:09:44 GMT</pubDate>
    <dc:creator>Shradha1</dc:creator>
    <dc:date>2021-07-12T06:09:44Z</dc:date>
    <item>
      <title>How to make a macro to loop through two non consecutive months?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-macro-to-loop-through-two-non-consecutive-months/m-p/753426#M237453</link>
      <description>&lt;P&gt;I am doing an analysis on data for 3 specific months: 202006, 202007, 202008.&lt;/P&gt;
&lt;P&gt;And for each of these 3 months, I want a macro loop, which will run only for M-1 and M+6 month where M takes the above three months as values. The starting part of my macro is this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET Mon_ST = 202006;			
%LET Mon_EN = 202008;			
Option obs = Max;			
			
%macro copy_data();			
			
%DO Mnth = &amp;amp;Mon_ST. %TO &amp;amp;Mon_EN. ;			
%IF %SUBSTR(&amp;amp;Mnth.,5,2) = 13 %THEN %LET Mnth =	%EVAL(%SUBSTR(&amp;amp;Mnth.,1,4)+1)01;	
%Put Mnth = &amp;amp;Mnth.;	&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now, I want to create another loop within this macro which will run for only two specific time periods for each of these months. For eaxample, when Mnth =202006, the loop will create another macro variable, say MON, which will first take value 202005 (Mnth-1) and on the next iteration will take value 202012 (Mnth+6). Similary,&amp;nbsp;when Mnth =202007, MON will first be equal to 202006, and then 202101.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do I create this sub loop? Any help will be much appreciated. Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jul 2021 06:09:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-macro-to-loop-through-two-non-consecutive-months/m-p/753426#M237453</guid>
      <dc:creator>Shradha1</dc:creator>
      <dc:date>2021-07-12T06:09:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a macro to loop through two non consecutive months?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-macro-to-loop-through-two-non-consecutive-months/m-p/753433#M237457</link>
      <description>&lt;P&gt;One way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let mon_st = 202006;			
%let mon_en = 202008;			
option obs = max;			
			
%macro copy_data();			
  %local mnth from to by m;
  %do mnth = &amp;amp;mon_st. %to &amp;amp;mon_en. ;			
    %if %substr(&amp;amp;mnth.,5,2) = 13 %then %let mnth = %eval(&amp;amp;mnth+100-12);	
    %put &amp;amp;=mnth;
    %let from= %sysfunc(intnx(month,%sysfunc(inputn(&amp;amp;mnth,yymmn6.)),-1),yymmn6.); 	
    %let to  = %sysfunc(intnx(month,%sysfunc(inputn(&amp;amp;mnth,yymmn6.)),+6),yymmn6.);
    %let by  = %eval(&amp;amp;to - &amp;amp;from);
    %do m=&amp;amp;from %to &amp;amp;to %by &amp;amp;by;
      %put &amp;amp;=m;
    %end;
  %end;
%mend;
%copy_data;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;MNTH=202006&lt;BR /&gt;M=202005&lt;BR /&gt;M=202012&lt;BR /&gt;MNTH=202007&lt;BR /&gt;M=202006&lt;BR /&gt;M=202101&lt;BR /&gt;MNTH=202008&lt;BR /&gt;M=202007&lt;BR /&gt;M=202102&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jul 2021 07:44:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-a-macro-to-loop-through-two-non-consecutive-months/m-p/753433#M237457</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-07-12T07:44:14Z</dc:date>
    </item>
  </channel>
</rss>

