<?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: create series of macro variables in form YYMM  from 2 months before &amp;amp;start until &amp;amp;end in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/create-series-of-macro-variables-in-form-YYMM-from-2-months/m-p/568676#M160140</link>
    <description>&lt;P&gt;Perfect solution.&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;I am still interested to know what is the error in my code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 25 Jun 2019 09:52:10 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2019-06-25T09:52:10Z</dc:date>
    <item>
      <title>create series of macro variables in form YYMM  from 2 months before &amp;start until &amp;end</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-series-of-macro-variables-in-form-YYMM-from-2-months/m-p/568638#M160106</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to create series of macro variables in form YYMM&amp;nbsp; from 2 months before &amp;amp;start until &amp;amp;end&lt;/P&gt;
&lt;P&gt;In this example start=1901&amp;nbsp; end=1903 so I want to create series of macro varaibles:&lt;/P&gt;
&lt;P&gt;m0=1811&lt;/P&gt;
&lt;P&gt;m1=1812&lt;/P&gt;
&lt;P&gt;m2=1901&lt;/P&gt;
&lt;P&gt;m3=1902&lt;/P&gt;
&lt;P&gt;m4=1903&lt;/P&gt;
&lt;P&gt;However, in the following code I get all macro parameter values equal 1903.&lt;/P&gt;
&lt;P&gt;What is the mistake in the logic please?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let start=1901;
%let end=1903;


%let date_start=%sysfunc(inputn(&amp;amp;start.,yymmn4.));
%let date_end=%sysfunc(inputn(&amp;amp;end.,yymmn4.));
%put &amp;amp;date_start.  ;/*21550*/
%put &amp;amp;date_end. ; /*21609*/


data _null_;
n1=intck('month',&amp;amp;date_start.,&amp;amp;date_end.);
n2=n1+2;
call symput("n1",trim(left(n1)));
call symput("n2",trim(left(n2)));
run;
%put &amp;amp;n1;
%put &amp;amp;n2;

%macro months;
%do i=-2 %to &amp;amp;n1.;
%do j=0 %to &amp;amp;n2.;
m&amp;amp;j.=put(intnx('month',&amp;amp;date_start.,&amp;amp;i.),yymmn4.);
call symput("m&amp;amp;j",trim(left(m&amp;amp;j.)));
%end;
%end;
%mend;

data aaa;
%months;
run;

%put &amp;amp;&amp;amp;m&amp;amp;n2;
%put &amp;amp;m0;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Jun 2019 06:35:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-series-of-macro-variables-in-form-YYMM-from-2-months/m-p/568638#M160106</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-06-25T06:35:29Z</dc:date>
    </item>
    <item>
      <title>Re: create series of macro variables in form YYMM  from 2 months before &amp;start until &amp;end</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-series-of-macro-variables-in-form-YYMM-from-2-months/m-p/568652#M160119</link>
      <description>&lt;P&gt;You are massively overcomplicating things by abusing the poor macro processor.&lt;/P&gt;
&lt;P&gt;Such things are easily done in one simple data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let start=1901;
%let end=1903;

data control;
start = intnx('month',input("&amp;amp;start",yymmn4.),-2,'b');
end = input("&amp;amp;end.",yymmn4.);
length month $4;
m = 0;
do until (start &amp;gt; end);
  month = put(start,yymmn4.);
  call symputx(cats('M',m),month);
  output;
  m + 1;
  start = intnx('month',start,1,'b');
end;
keep month;
run;

%put &amp;amp;m0 &amp;amp;m1 &amp;amp;m2 &amp;amp;m3 &amp;amp;m4;

proc print data=control noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log excerpt:&lt;/P&gt;
&lt;PRE&gt;42         %put &amp;amp;m0 &amp;amp;m1 &amp;amp;m2 &amp;amp;m3 &amp;amp;m4;
1811 1812 1901 1902 1903
&lt;/PRE&gt;
&lt;P&gt;Result of print:&lt;/P&gt;
&lt;PRE&gt;month

1811 
1812 
1901 
1902 
1903 
&lt;/PRE&gt;
&lt;P&gt;I created the dataset because data has to be kept in datasets, not unwieldy macro variable lists. The control dataset can easily be used to create dynamic code with call execute.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jun 2019 08:25:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-series-of-macro-variables-in-form-YYMM-from-2-months/m-p/568652#M160119</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-06-25T08:25:13Z</dc:date>
    </item>
    <item>
      <title>Re: create series of macro variables in form YYMM  from 2 months before &amp;start until &amp;end</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-series-of-macro-variables-in-form-YYMM-from-2-months/m-p/568676#M160140</link>
      <description>&lt;P&gt;Perfect solution.&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;I am still interested to know what is the error in my code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jun 2019 09:52:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-series-of-macro-variables-in-form-YYMM-from-2-months/m-p/568676#M160140</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-06-25T09:52:10Z</dc:date>
    </item>
    <item>
      <title>Re: create series of macro variables in form YYMM  from 2 months before &amp;start until &amp;end</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-series-of-macro-variables-in-form-YYMM-from-2-months/m-p/568682#M160142</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;Perfect solution.&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;I am still interested to know what is the error in my code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Your use of two nested %do loops. When the outer loop reaches 1903, the inner loop overwrites all variables.&lt;/P&gt;
&lt;P&gt;Even that logic does not need any macro code at all:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data aaa;
array m {%eval(&amp;amp;n2.+1)} m0-m&amp;amp;n2.;
format m0-m&amp;amp;n2. yymmn4.;
do i = 0 to &amp;amp;n2.;
  m{i+1} = intnx('month',&amp;amp;date_start.,i-2);
end;
drop i;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Maxim 11&lt;/P&gt;
&lt;P&gt;Maxim 11&lt;/P&gt;
&lt;P&gt;Maxim 11&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jun 2019 10:15:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-series-of-macro-variables-in-form-YYMM-from-2-months/m-p/568682#M160142</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-06-25T10:15:59Z</dc:date>
    </item>
    <item>
      <title>Re: create series of macro variables in form YYMM  from 2 months before &amp;start until &amp;end</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-series-of-macro-variables-in-form-YYMM-from-2-months/m-p/568784#M160189</link>
      <description>&lt;P&gt;I believe nearly 2 years ago when you started posting and were using "dates" in this form YYMM&amp;nbsp;I mentioned that actually using a date value and using an appropriate format to display the date would be easier in the long run.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am not sure but I suspect this is at least the 20th post you have regarding manipulating dates in this non-date form.&lt;/P&gt;
&lt;P&gt;Note that the first thing you have to do each an every time is build a date value to increment or manipulate things.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have not seen anything where use of YYMM appearing numeric values&amp;nbsp;has made any of your tasks simpler or easier to follow.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jul 2019 16:25:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-series-of-macro-variables-in-form-YYMM-from-2-months/m-p/568784#M160189</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-07-08T16:25:56Z</dc:date>
    </item>
  </channel>
</rss>

