<?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: Loop Do-error in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Loop-Do-error/m-p/666594#M199475</link>
    <description>&lt;P&gt;An alternative is to code generate four sets of&amp;nbsp;&lt;EM&gt;assignment, &lt;/EM&gt;followed by&lt;EM&gt; output&lt;/EM&gt; statements&amp;nbsp;.&amp;nbsp; In this scenario the looping would be a macro &lt;CODE&gt;%DO&lt;/CODE&gt; loop and necessarily be inside a macro definition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;%macro learning;
  %let YYMM1=2005;
  %let YYMM2=1809;
  %let YYMM3=1912;
  %let YYMM4=1812;
  data c;
    %DO i = 1 %to 4;
      vec =&amp;amp;&amp;amp;YYMM&amp;amp;i;
      output;
    %END;
  run;
%mend;

options mprint;
%learning&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Log&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;15   %learning
MPRINT(LEARNING):   data c;
MPRINT(LEARNING):   vec =2005;
MPRINT(LEARNING):   output;
MPRINT(LEARNING):   vec =1809;
MPRINT(LEARNING):   output;
MPRINT(LEARNING):   vec =1912;
MPRINT(LEARNING):   output;
MPRINT(LEARNING):   vec =1812;
MPRINT(LEARNING):   output;
MPRINT(LEARNING):   run;
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Suppose you manage a race car pit stop.&amp;nbsp; The car comes in, what do you do ?&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Change the tires and keep the car (SYMGET), or&lt;/LI&gt;
&lt;LI&gt;Keep the tires and change the car (codegen)?&lt;/LI&gt;
&lt;/UL&gt;</description>
    <pubDate>Thu, 02 Jul 2020 14:04:04 GMT</pubDate>
    <dc:creator>RichardDeVen</dc:creator>
    <dc:date>2020-07-02T14:04:04Z</dc:date>
    <item>
      <title>Loop Do-error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-Do-error/m-p/666547#M199453</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;What is the reason for error here?&lt;/P&gt;
&lt;P&gt;This code has no special meaning but I want to learn it&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The error is:&lt;/P&gt;
&lt;P&gt;WARNING: Apparent symbolic reference I not resolved.&lt;BR /&gt;NOTE: Line generated by the macro variable "I".&lt;BR /&gt;32 &amp;amp;YYMM&amp;amp;&lt;BR /&gt;_&lt;BR /&gt;22&lt;BR /&gt;WARNING: Apparent symbolic reference YYMM not resolved.&lt;BR /&gt;WARNING: Apparent symbolic reference I not resolved.&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant, &lt;BR /&gt;a missing value, INPUT, PUT.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let YYMM1=2005;
%let YYMM2=1809;
%let YYMM3=1912;
%let YYMM4=1812;
data c;
do i = 1 to 4;
vec =&amp;amp;&amp;amp;YYMM&amp;amp;i;
output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Jul 2020 05:53:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-Do-error/m-p/666547#M199453</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-07-02T05:53:00Z</dc:date>
    </item>
    <item>
      <title>Re: Loop Do-error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-Do-error/m-p/666550#M199454</link>
      <description>&lt;P&gt;The variable i is a data-step variable, but you are using it as a macro-variable. Try something like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;vec = resolve(cats('&amp;amp;YYMM', i));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;instead.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jul 2020 06:06:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-Do-error/m-p/666550#M199454</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-07-02T06:06:44Z</dc:date>
    </item>
    <item>
      <title>Re: Loop Do-error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-Do-error/m-p/666552#M199455</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;What is the reason for error here?&lt;/P&gt;
&lt;P&gt;This code has no special meaning but I want to learn it&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The error is:&lt;/P&gt;
&lt;P&gt;WARNING: Apparent symbolic reference I not resolved.&lt;BR /&gt;NOTE: Line generated by the macro variable "I".&lt;BR /&gt;32 &amp;amp;YYMM&amp;amp;&lt;BR /&gt;_&lt;BR /&gt;22&lt;BR /&gt;WARNING: Apparent symbolic reference YYMM not resolved.&lt;BR /&gt;WARNING: Apparent symbolic reference I not resolved.&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant, &lt;BR /&gt;a missing value, INPUT, PUT.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let YYMM1=2005;
%let YYMM2=1809;
%let YYMM3=1912;
%let YYMM4=1812;
data c;
do i = 1 to 4;
vec =&amp;amp;&amp;amp;YYMM&amp;amp;i;
output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;You really need to start now to make use of the documentation, in this case, the chapter about &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=mcrolref&amp;amp;docsetTarget=n1i6e38icri48mn1dxvn0m7kvzsx.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;Data Step Interfaces&lt;/A&gt;&amp;nbsp; of the macro facility.&lt;/P&gt;
&lt;P&gt;There you will find the&amp;nbsp;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=mcrolref&amp;amp;docsetTarget=n00cqfgax81a11n1oww7hwno4aae.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;SYMGET Function&lt;/A&gt;&amp;nbsp;, which is the tool of choice to read the value of a macro variable dynamically in a data step:&lt;/P&gt;
&lt;PRE&gt;%let YYMM1=2005;
%let YYMM2=1809;
%let YYMM3=1912;
%let YYMM4=1812;

data c;
do i = 1 to 4;
  vec = symget(cats('YYMM',i));
  output;
end;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Jul 2020 06:12:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-Do-error/m-p/666552#M199455</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-07-02T06:12:40Z</dc:date>
    </item>
    <item>
      <title>Re: Loop Do-error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-Do-error/m-p/666594#M199475</link>
      <description>&lt;P&gt;An alternative is to code generate four sets of&amp;nbsp;&lt;EM&gt;assignment, &lt;/EM&gt;followed by&lt;EM&gt; output&lt;/EM&gt; statements&amp;nbsp;.&amp;nbsp; In this scenario the looping would be a macro &lt;CODE&gt;%DO&lt;/CODE&gt; loop and necessarily be inside a macro definition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;%macro learning;
  %let YYMM1=2005;
  %let YYMM2=1809;
  %let YYMM3=1912;
  %let YYMM4=1812;
  data c;
    %DO i = 1 %to 4;
      vec =&amp;amp;&amp;amp;YYMM&amp;amp;i;
      output;
    %END;
  run;
%mend;

options mprint;
%learning&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Log&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;15   %learning
MPRINT(LEARNING):   data c;
MPRINT(LEARNING):   vec =2005;
MPRINT(LEARNING):   output;
MPRINT(LEARNING):   vec =1809;
MPRINT(LEARNING):   output;
MPRINT(LEARNING):   vec =1912;
MPRINT(LEARNING):   output;
MPRINT(LEARNING):   vec =1812;
MPRINT(LEARNING):   output;
MPRINT(LEARNING):   run;
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Suppose you manage a race car pit stop.&amp;nbsp; The car comes in, what do you do ?&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Change the tires and keep the car (SYMGET), or&lt;/LI&gt;
&lt;LI&gt;Keep the tires and change the car (codegen)?&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Thu, 02 Jul 2020 14:04:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-Do-error/m-p/666594#M199475</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-07-02T14:04:04Z</dc:date>
    </item>
  </channel>
</rss>

