<?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: call symput with a do loop in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/call-symput-with-a-do-loop/m-p/506892#M1414</link>
    <description>&lt;P&gt;You can use a DO loop, but you need to reference the variable you are looping over when making the macro variable names.&lt;/P&gt;
&lt;P&gt;Referencing some undefined macro variable is not going be very helpful.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  do i=1 to 5;
   CALL SYMPUTX(cats('MONTH',i),PUT(INTNX('MONTH',today(),-i,'b'),monyy.));
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also make sure to use the newer CALL SYMPUTX() function instead of the old CALL SYMPUT() function.&amp;nbsp; Unless you really NEED to store non macro quoted trailing blanks into your macro variables.&lt;/P&gt;</description>
    <pubDate>Tue, 23 Oct 2018 16:05:18 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-10-23T16:05:18Z</dc:date>
    <item>
      <title>call symput with a do loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/call-symput-with-a-do-loop/m-p/506887#M1411</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to find a shorter way of creating a range of macro variables with dates&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the code I would usually use is below but I'm finding this is getting longer and longer as I'm now going back 12 months&amp;nbsp;+&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA _null_;
CALL SYMPUT('THIS_MONTH',PUT(INTNX('Month',today(),0,'b'),monyy.));
CALL SYMPUT('MONTH1',PUT(INTNX('Month',today(),-1,'b'),monyy.));
...
CALL SYMPUT('MONTH26',PUT(INTNX('Month',today(),-1,'b'),monyy.));
run;
%put &amp;amp;THIS_MONTH;
%put &amp;amp;MONTH1;
...
%put &amp;amp;MONTH26;&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;I was hoping that the same would be possible using a do loop... something along the lines of&amp;nbsp;&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;data _null_;
do i=1 to i=5;
CALL SYMPUT('MONTH&amp;amp;i',PUT(INTNX('MONTH',today(),-&amp;amp;i.,'b'),monyy.));
end;
run;

%put &amp;amp;MONTH1;
%put &amp;amp;MONTH2;&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;the error I get in the log is&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;DIV class="sasSource"&gt;85 data _null_;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;86 do i=1 to i=5;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;87 CALL SYMPUT('MONTH&amp;amp;i',PUT(INTNX('MONTH',today(),-&amp;amp;i.,'b'),monyy.));&lt;/DIV&gt;&lt;DIV class="sasError"&gt;_&lt;/DIV&gt;&lt;DIV class="sasError"&gt;386&lt;/DIV&gt;&lt;DIV class="sasError"&gt;200&lt;/DIV&gt;&lt;DIV class="sasWarning"&gt;WARNING: Apparent symbolic reference I not resolved.&lt;/DIV&gt;&lt;DIV class="sasError"&gt;ERROR 386-185: Expecting an arithmetic expression.&lt;/DIV&gt;&lt;DIV class="sasError"&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;Is this to do with the CALL SYMPUT executing before the 1st iteration of the do loop has completed and therefore not knowing the value of &amp;amp;i?&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;Alternative suggestions would be much appreciated&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;Thank you!&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Oct 2018 15:56:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/call-symput-with-a-do-loop/m-p/506887#M1411</guid>
      <dc:creator>twenty7</dc:creator>
      <dc:date>2018-10-23T15:56:43Z</dc:date>
    </item>
    <item>
      <title>Re: call symput with a do loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/call-symput-with-a-do-loop/m-p/506892#M1414</link>
      <description>&lt;P&gt;You can use a DO loop, but you need to reference the variable you are looping over when making the macro variable names.&lt;/P&gt;
&lt;P&gt;Referencing some undefined macro variable is not going be very helpful.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  do i=1 to 5;
   CALL SYMPUTX(cats('MONTH',i),PUT(INTNX('MONTH',today(),-i,'b'),monyy.));
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also make sure to use the newer CALL SYMPUTX() function instead of the old CALL SYMPUT() function.&amp;nbsp; Unless you really NEED to store non macro quoted trailing blanks into your macro variables.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Oct 2018 16:05:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/call-symput-with-a-do-loop/m-p/506892#M1414</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-10-23T16:05:18Z</dc:date>
    </item>
    <item>
      <title>Re: call symput with a do loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/call-symput-with-a-do-loop/m-p/506895#M1416</link>
      <description>macro variables resolve in double quotes not single quotes. &lt;BR /&gt;You can loop, but change the first parameter to :&lt;BR /&gt;&lt;BR /&gt;call symputx(catt('VAR', put(i, z2. -l)) , &amp;lt;your formula&amp;gt;);</description>
      <pubDate>Tue, 23 Oct 2018 16:06:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/call-symput-with-a-do-loop/m-p/506895#M1416</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-23T16:06:06Z</dc:date>
    </item>
    <item>
      <title>Re: call symput with a do loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/call-symput-with-a-do-loop/m-p/506900#M1418</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/91983"&gt;@twenty7&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to find a shorter way of creating a range of macro variables with dates&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the code I would usually use is below but I'm finding this is getting longer and longer as I'm now going back 12 months&amp;nbsp;+&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA _null_;
CALL SYMPUT('THIS_MONTH',PUT(INTNX('Month',today(),0,'b'),monyy.));
CALL SYMPUT('MONTH1',PUT(INTNX('Month',today(),-1,'b'),monyy.));
...
CALL SYMPUT('MONTH26',PUT(INTNX('Month',today(),-1,'b'),monyy.));
run;
%put &amp;amp;THIS_MONTH;
%put &amp;amp;MONTH1;
...
%put &amp;amp;MONTH26;&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;I was hoping that the same would be possible using a do loop... something along the lines of&amp;nbsp;&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;data _null_;
do i=1 to i=5;
CALL SYMPUT('MONTH&amp;amp;i',PUT(INTNX('MONTH',today(),-&amp;amp;i.,'b'),monyy.));
end;
run;

%put &amp;amp;MONTH1;
%put &amp;amp;MONTH2;&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;the error I get in the log is&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;DIV class="sasSource"&gt;85 data _null_;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;86 do i=1 to i=5;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;87 CALL SYMPUT('MONTH&amp;amp;i',PUT(INTNX('MONTH',today(),-&amp;amp;i.,'b'),monyy.));&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;_&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;386&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;200&lt;/DIV&gt;
&lt;DIV class="sasWarning"&gt;WARNING: Apparent symbolic reference I not resolved.&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;ERROR 386-185: Expecting an arithmetic expression.&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/BLOCKQUOTE&gt;
&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;Is this to do with the CALL SYMPUT executing before the 1st iteration of the do loop has completed and therefore not knowing the value of &amp;amp;i?&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;Alternative suggestions would be much appreciated&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;Thank you!&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Several problems. A do loop is&lt;/P&gt;
&lt;PRE&gt;do I = 1 to 5;&lt;/PRE&gt;
&lt;P&gt;Not do I=1 to I=5;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You do not define a &lt;STRONG&gt;macro variable i&lt;/STRONG&gt;. If you paste code and messages from the log the indicator underscore would be under the &amp;amp;i . Data step values aren't referenced with macro &amp;amp;. Second, you are attempting to&amp;nbsp;create a macro variable&amp;nbsp;'month&amp;amp;i'. Within single quotes the&amp;nbsp;&amp;amp;I would not resolve to values anyway and results in an improper macro variable name.&lt;/P&gt;
&lt;P&gt;Solution: create a string variable&amp;nbsp;to hold the macro variable name, build the name and then use that in the call symput&lt;/P&gt;
&lt;PRE&gt;data _null_;
   length mvar $ 10;
   do i=1 to 5;
      mvar=cats('MONTH',i);
      CALL SYMPUTx(mvar,PUT(INTNX('MONTH',today(),-i,'b'),monyy.));
   end;
run;&lt;/PRE&gt;
&lt;P&gt;if you are going to create many of these variables make sure the length of mvar is long enough to hold the longest.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Recommend using CALL SYMPUTX to prevent odd blanks appearing at the ends of values.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Oct 2018 16:11:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/call-symput-with-a-do-loop/m-p/506900#M1418</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-10-23T16:11:59Z</dc:date>
    </item>
  </channel>
</rss>

