<?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: Change macro variable with each iteration (plus and minus) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Change-macro-variable-with-each-iteration-plus-and-minus/m-p/831032#M328392</link>
    <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro Loop_year(startyear=, endyear=);
   %DO I = &amp;amp;startyear %TO &amp;amp;endyear;
      %put YM1 is %eval(&amp;amp;I-1);   
	   %put Y   is &amp;amp;I;
	   %put YP1 is %eval(&amp;amp;I+1);
   %end;
%mend Loop_year;

%Loop_year(startyear=2011, endyear=2013);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Result:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;YM1 is 2010
Y   is 2011
YP1 is 2012
YM1 is 2011
Y   is 2012
YP1 is 2013
YM1 is 2012
Y   is 2013
YP1 is 2014&lt;/PRE&gt;</description>
    <pubDate>Tue, 30 Aug 2022 04:40:05 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2022-08-30T04:40:05Z</dc:date>
    <item>
      <title>Change macro variable with each iteration (plus and minus)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-macro-variable-with-each-iteration-plus-and-minus/m-p/831031#M328391</link>
      <description>&lt;P&gt;I would like a macro variable that is referenced to change -1 and +1 with each iteration. For example in the following loop, each iteration from the start year of 2011 to the end year of 2013 should give the year minus 1 (YM1), the year (Y), and the year plus 1 (YP1).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro Loop_year(startyear=, endyear=);
   %DO I = &amp;amp;startyear %TO &amp;amp;endyear;
      %put YM1 is &amp;amp;I-1;   
	  %put Y   is &amp;amp;I;
	  %put YP1 is &amp;amp;I+1;
   %end;
%mend Loop_year;

%Loop_year(startyear=2011, endyear=2013);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;This is what I get:&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;YM1 is 2011-1&lt;BR /&gt;Y is 2011&lt;BR /&gt;YP1 is 2011+1&lt;BR /&gt;YM1 is 2012-1&lt;BR /&gt;Y is 2012&lt;BR /&gt;YP1 is 2012+1&lt;BR /&gt;YM1 is 2013-1&lt;BR /&gt;Y is 2013&lt;BR /&gt;YP1 is 2013+1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;But this is what I want:&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;YM1 is 2010&lt;BR /&gt;Y is 2011&lt;BR /&gt;YP1 is 2012&lt;BR /&gt;YM1 is 2011&lt;BR /&gt;Y is 2012&lt;BR /&gt;YP1 is 2013&lt;BR /&gt;YM1 is 2012&lt;BR /&gt;Y is 2013&lt;BR /&gt;YP1 is 2014&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Would this be possible? Thanks in advance&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2022 04:32:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-macro-variable-with-each-iteration-plus-and-minus/m-p/831031#M328391</guid>
      <dc:creator>DougHold</dc:creator>
      <dc:date>2022-08-30T04:32:34Z</dc:date>
    </item>
    <item>
      <title>Re: Change macro variable with each iteration (plus and minus)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-macro-variable-with-each-iteration-plus-and-minus/m-p/831032#M328392</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro Loop_year(startyear=, endyear=);
   %DO I = &amp;amp;startyear %TO &amp;amp;endyear;
      %put YM1 is %eval(&amp;amp;I-1);   
	   %put Y   is &amp;amp;I;
	   %put YP1 is %eval(&amp;amp;I+1);
   %end;
%mend Loop_year;

%Loop_year(startyear=2011, endyear=2013);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Result:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;YM1 is 2010
Y   is 2011
YP1 is 2012
YM1 is 2011
Y   is 2012
YP1 is 2013
YM1 is 2012
Y   is 2013
YP1 is 2014&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Aug 2022 04:40:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-macro-variable-with-each-iteration-plus-and-minus/m-p/831032#M328392</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-08-30T04:40:05Z</dc:date>
    </item>
    <item>
      <title>Re: Change macro variable with each iteration (plus and minus)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-macro-variable-with-each-iteration-plus-and-minus/m-p/831082#M328416</link>
      <description>Exactly, thank you! The %eval() is what I was looking for.&lt;BR /&gt;</description>
      <pubDate>Tue, 30 Aug 2022 12:40:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-macro-variable-with-each-iteration-plus-and-minus/m-p/831082#M328416</guid>
      <dc:creator>DougHold</dc:creator>
      <dc:date>2022-08-30T12:40:02Z</dc:date>
    </item>
  </channel>
</rss>

