<?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 series of YYMM in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/series-of-YYMM/m-p/731504#M227856</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;User define base month in a structure of YYMM (Macro variable).&lt;/P&gt;
&lt;P&gt;Then I want to create automatically 6 macro variables called: Back0,Back1,Back2,Back3,Back4,Back5&amp;nbsp; which are 0/1/2/3/4/5 months previous months&amp;nbsp; of base month.&lt;/P&gt;
&lt;P&gt;I also want to create&amp;nbsp;automatically 6 macro variables called: month6,month5,month4,month3,month2,month1&amp;nbsp; which are equal to macro variables&amp;nbsp;Back0,Back1,Back2,Back3,Back4,Back5&amp;nbsp; (month6 eual to&amp;nbsp;Back0,month5 equal to&amp;nbsp;Back1 and so on).&lt;/P&gt;
&lt;P&gt;What is the way to solve the problem with statement k-1?&lt;/P&gt;
&lt;P&gt;I know that I can do it in the following way&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let month6=&amp;amp;back0;&lt;BR /&gt;%let month5=&amp;amp;back1;&lt;BR /&gt;%let month4=&amp;amp;back2;&lt;BR /&gt;%let month3=&amp;amp;back3;&lt;BR /&gt;%let month2=&amp;amp;back4;&lt;BR /&gt;%let month1=&amp;amp;back5;&lt;/P&gt;
&lt;P&gt;But I want to understand what is the problem with k-1 statement and how to solve it?&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;%let baseMon=1811;
data tbl;
EndMon = intnx('month',input("&amp;amp;baseMon",yymmn4.),0,'b');/*initial start date*/
startMon = intnx('month',input("&amp;amp;baseMon",yymmn4.),-5,'b');/*End date*/
length YYMM $4;
j=0;
k=6;
do until (startMon &amp;gt; EndMon);
  YYMM = put(EndMon,yymmn4.);
  back=cats('back',j);
  month=cats('month',k);
  call symputx(cats('back',j),YYMM);
  call symputx(cats('month',k),YYMM);
  output;
  j+1;
  k-1;/*Here is the problem. When I write k+1 it works but I need k-1 for my purpose*/
  EndMon = intnx('month',EndMon,-1,'b');
end;
keep YYMM back month;
run;
/**Results that I want to get are:**/
%put &amp;amp;back0;/*1811*/
%put &amp;amp;back1;/*1810*/
%put &amp;amp;back2;/*1809*/
%put &amp;amp;back3;/*1808*/
%put &amp;amp;back4;/*1807*/
%put &amp;amp;back5;/*1806*/

%put &amp;amp;month6;/*1811*/
%put &amp;amp;month5;/*1810*/
%put &amp;amp;month4;/*1809*/
%put &amp;amp;month3;/*1808*/
%put &amp;amp;month2;/*1807*/
%put &amp;amp;month1;/*1806*/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 06 Apr 2021 04:37:59 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2021-04-06T04:37:59Z</dc:date>
    <item>
      <title>series of YYMM</title>
      <link>https://communities.sas.com/t5/SAS-Programming/series-of-YYMM/m-p/731504#M227856</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;User define base month in a structure of YYMM (Macro variable).&lt;/P&gt;
&lt;P&gt;Then I want to create automatically 6 macro variables called: Back0,Back1,Back2,Back3,Back4,Back5&amp;nbsp; which are 0/1/2/3/4/5 months previous months&amp;nbsp; of base month.&lt;/P&gt;
&lt;P&gt;I also want to create&amp;nbsp;automatically 6 macro variables called: month6,month5,month4,month3,month2,month1&amp;nbsp; which are equal to macro variables&amp;nbsp;Back0,Back1,Back2,Back3,Back4,Back5&amp;nbsp; (month6 eual to&amp;nbsp;Back0,month5 equal to&amp;nbsp;Back1 and so on).&lt;/P&gt;
&lt;P&gt;What is the way to solve the problem with statement k-1?&lt;/P&gt;
&lt;P&gt;I know that I can do it in the following way&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let month6=&amp;amp;back0;&lt;BR /&gt;%let month5=&amp;amp;back1;&lt;BR /&gt;%let month4=&amp;amp;back2;&lt;BR /&gt;%let month3=&amp;amp;back3;&lt;BR /&gt;%let month2=&amp;amp;back4;&lt;BR /&gt;%let month1=&amp;amp;back5;&lt;/P&gt;
&lt;P&gt;But I want to understand what is the problem with k-1 statement and how to solve it?&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;%let baseMon=1811;
data tbl;
EndMon = intnx('month',input("&amp;amp;baseMon",yymmn4.),0,'b');/*initial start date*/
startMon = intnx('month',input("&amp;amp;baseMon",yymmn4.),-5,'b');/*End date*/
length YYMM $4;
j=0;
k=6;
do until (startMon &amp;gt; EndMon);
  YYMM = put(EndMon,yymmn4.);
  back=cats('back',j);
  month=cats('month',k);
  call symputx(cats('back',j),YYMM);
  call symputx(cats('month',k),YYMM);
  output;
  j+1;
  k-1;/*Here is the problem. When I write k+1 it works but I need k-1 for my purpose*/
  EndMon = intnx('month',EndMon,-1,'b');
end;
keep YYMM back month;
run;
/**Results that I want to get are:**/
%put &amp;amp;back0;/*1811*/
%put &amp;amp;back1;/*1810*/
%put &amp;amp;back2;/*1809*/
%put &amp;amp;back3;/*1808*/
%put &amp;amp;back4;/*1807*/
%put &amp;amp;back5;/*1806*/

%put &amp;amp;month6;/*1811*/
%put &amp;amp;month5;/*1810*/
%put &amp;amp;month4;/*1809*/
%put &amp;amp;month3;/*1808*/
%put &amp;amp;month2;/*1807*/
%put &amp;amp;month1;/*1806*/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Apr 2021 04:37:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/series-of-YYMM/m-p/731504#M227856</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-04-06T04:37:59Z</dc:date>
    </item>
    <item>
      <title>Re: series of YYMM</title>
      <link>https://communities.sas.com/t5/SAS-Programming/series-of-YYMM/m-p/731507#M227858</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;User define base month in a structure of YYMM (Macro variable).&lt;/P&gt;
&lt;P&gt;Then I want to create automatically 6 macro variables called: Back0,Back1,Back2,Back3,Back4,Back5&amp;nbsp; which are 0/1/2/3/4/5 months previous months&amp;nbsp; of base month.&lt;/P&gt;
&lt;P&gt;I also want to create&amp;nbsp;automatically 6 macro variables called: month6,month5,month4,month3,month2,month1&amp;nbsp; which are equal to macro variables&amp;nbsp;Back0,Back1,Back2,Back3,Back4,Back5&amp;nbsp; (month6 eual to&amp;nbsp;Back0,month5 equal to&amp;nbsp;Back1 and so on).&lt;/P&gt;
&lt;P&gt;What is the way to solve the problem with statement k-1?&lt;/P&gt;
&lt;P&gt;I know that I can do it in the following way&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let month6=&amp;amp;back0;&lt;BR /&gt;%let month5=&amp;amp;back1;&lt;BR /&gt;%let month4=&amp;amp;back2;&lt;BR /&gt;%let month3=&amp;amp;back3;&lt;BR /&gt;%let month2=&amp;amp;back4;&lt;BR /&gt;%let month1=&amp;amp;back5;&lt;/P&gt;
&lt;P&gt;But I want to understand what is the problem with k-1 statement and how to solve it?&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;  k-1;/*Here is the problem. When I write k+1 it works but I need k-1 for my purpose*/
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The problem is that the statement&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; k+1;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;is a summing statement.&amp;nbsp; Which means that (1) missing k will be treated as a zero, and (2) k will be retained over iterations of the data step.&amp;nbsp; &amp;nbsp;Since you are doing iterations over a do loop, instead of over multiple data set iterations, you could just as well do k=sum(k,1).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;k-1;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;is NOT such a statement.&amp;nbsp; But you could do&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;k=sum(k,-1);&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Or if you like the summing statement format you could do&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;k+(-1);&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Tue, 06 Apr 2021 04:58:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/series-of-YYMM/m-p/731507#M227858</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-04-06T04:58:11Z</dc:date>
    </item>
    <item>
      <title>Re: series of YYMM</title>
      <link>https://communities.sas.com/t5/SAS-Programming/series-of-YYMM/m-p/731518#M227866</link>
      <description>&lt;P&gt;Too complicated, build the inversion with a simple subtraction:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let baseMon=201811;
%let number=6;

data _null_;
do i = 0 to &amp;amp;number.;
  em = put(intnx('month',input("&amp;amp;basemon.",yymmn6.),-i,'b'),yymmn6.);
  call symputx(cats('back',i),em);
  call symputx(cats('month',&amp;amp;number. - i),em);
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Apr 2021 07:03:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/series-of-YYMM/m-p/731518#M227866</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-04-06T07:03:29Z</dc:date>
    </item>
  </channel>
</rss>

