<?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: My code doesn't want to work inside a DO loop- not accessing value? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/My-code-doesn-t-want-to-work-inside-a-DO-loop-not-accessing/m-p/393757#M94852</link>
    <description>&lt;P&gt;If it does absolutely nothing then perhaps it is because you never called it?&lt;/P&gt;
&lt;P&gt;Also you are referencing an undefined macro where I think you want to reference an macro variable.&lt;/P&gt;
&lt;P&gt;If your going to the trouble of making a macro you might as well use some parameters.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro my_yearly_stuff(startyr,endyr); 
%local year;
%do year = &amp;amp;startyr %to &amp;amp;endyr;

... code block- all my working statements calling &amp;amp;year here

%end; 
%mend my_yearly_stuff;

%my_yearly_stuff(15,18);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 07 Sep 2017 04:45:51 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2017-09-07T04:45:51Z</dc:date>
    <item>
      <title>My code doesn't want to work inside a DO loop- not accessing value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/My-code-doesn-t-want-to-work-inside-a-DO-loop-not-accessing/m-p/393717#M94836</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hey,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have code like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let year = 15;

DATA my_new_file_&amp;amp;year;                           
   SET source_file&amp;amp;year;
calculate stuff;
make things;
run;

proc freq data = my_new_file_&amp;amp;year;
	tables variable;
	format;
	title "&amp;amp;year stuff";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;that works fine and is very useful&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When i want to do 16 (or 17 or 18) I copy and past the block of code and make&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let year = 16;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or whatever year I want to run.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;What I want to do is something like &lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro my_yearly_stuff; 
%do myyear = 15 %to 18;
&lt;BR /&gt;%let year = %myyear
code block- all my working statements calling &amp;amp;year here

%end; 
%mend my_yearly_stuff;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Run all the statement in a loop that iterates from 15 to 18 and executes the code block for each year.&amp;nbsp;&amp;nbsp; But when I do that I get nothing.&amp;nbsp; No error.&amp;nbsp; No warning. Just nothing. The code is echoed in the log window but nothing happens.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What am i doing wrong?&amp;nbsp; How do i access the value of myyear and get it into the code? &lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2017 21:25:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/My-code-doesn-t-want-to-work-inside-a-DO-loop-not-accessing/m-p/393717#M94836</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2017-09-06T21:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: My code doesn't want to work inside a DO loop- not accessing value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/My-code-doesn-t-want-to-work-inside-a-DO-loop-not-accessing/m-p/393721#M94838</link>
      <description>&lt;P&gt;Change the %myyear to &amp;amp;myyear and make sure to end the statement with a semi-colon&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2017 21:39:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/My-code-doesn-t-want-to-work-inside-a-DO-loop-not-accessing/m-p/393721#M94838</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-09-06T21:39:14Z</dc:date>
    </item>
    <item>
      <title>Re: My code doesn't want to work inside a DO loop- not accessing value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/My-code-doesn-t-want-to-work-inside-a-DO-loop-not-accessing/m-p/393731#M94842</link>
      <description>&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macrobound"&gt;%macro&lt;/SPAN&gt; my_yearly_stuff&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; 
&lt;SPAN class="token macrostatement"&gt;%do&lt;/SPAN&gt; myyear &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;15&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%to&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;18&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token macroname"&gt;%let&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;year&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token macroname"&gt;%myyear -&amp;gt; not needed, use the myYear macro variable directly. &lt;/SPAN&gt;
code block&lt;SPAN class="token operator"&gt;-&lt;/SPAN&gt; all my working statements calling &lt;SPAN class="token operator"&gt;&amp;amp;myY&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;ear&lt;/SPAN&gt; here

&lt;SPAN class="token macrostatement"&gt;%end&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; 
&lt;SPAN class="token macrobound"&gt;%mend&lt;/SPAN&gt; my_yearly_stuff&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note the small changes needed.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2017 22:26:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/My-code-doesn-t-want-to-work-inside-a-DO-loop-not-accessing/m-p/393731#M94842</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-09-06T22:26:46Z</dc:date>
    </item>
    <item>
      <title>Re: My code doesn't want to work inside a DO loop- not accessing value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/My-code-doesn-t-want-to-work-inside-a-DO-loop-not-accessing/m-p/393757#M94852</link>
      <description>&lt;P&gt;If it does absolutely nothing then perhaps it is because you never called it?&lt;/P&gt;
&lt;P&gt;Also you are referencing an undefined macro where I think you want to reference an macro variable.&lt;/P&gt;
&lt;P&gt;If your going to the trouble of making a macro you might as well use some parameters.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro my_yearly_stuff(startyr,endyr); 
%local year;
%do year = &amp;amp;startyr %to &amp;amp;endyr;

... code block- all my working statements calling &amp;amp;year here

%end; 
%mend my_yearly_stuff;

%my_yearly_stuff(15,18);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2017 04:45:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/My-code-doesn-t-want-to-work-inside-a-DO-loop-not-accessing/m-p/393757#M94852</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-09-07T04:45:51Z</dc:date>
    </item>
    <item>
      <title>Re: My code doesn't want to work inside a DO loop- not accessing value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/My-code-doesn-t-want-to-work-inside-a-DO-loop-not-accessing/m-p/393760#M94855</link>
      <description>%macro my_yearly_stuff;&lt;BR /&gt;%do myyear = 15 %to 18;&lt;BR /&gt;*%let year = %myyear; *Not required (IMO);&lt;BR /&gt;code block- all my working statements calling &amp;amp;myyear. here&lt;BR /&gt;&lt;BR /&gt;%end;&lt;BR /&gt;%mend my_yearly_stuff;</description>
      <pubDate>Thu, 07 Sep 2017 04:54:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/My-code-doesn-t-want-to-work-inside-a-DO-loop-not-accessing/m-p/393760#M94855</guid>
      <dc:creator>ShiroAmada</dc:creator>
      <dc:date>2017-09-07T04:54:43Z</dc:date>
    </item>
    <item>
      <title>Re: My code doesn't want to work inside a DO loop- not accessing value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/My-code-doesn-t-want-to-work-inside-a-DO-loop-not-accessing/m-p/393916#M94897</link>
      <description>&lt;P&gt;We have a winner.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I wasn't calling it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I had&lt;/P&gt;
&lt;P&gt;%mend my_yearly_stuff;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;which is exactly what the example showed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I changed that to&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%mend; &lt;BR /&gt;%my_yearly_stuff;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and it runs.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2017 15:18:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/My-code-doesn-t-want-to-work-inside-a-DO-loop-not-accessing/m-p/393916#M94897</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2017-09-07T15:18:30Z</dc:date>
    </item>
    <item>
      <title>Re: My code doesn't want to work inside a DO loop- not accessing value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/My-code-doesn-t-want-to-work-inside-a-DO-loop-not-accessing/m-p/393928#M94899</link>
      <description>&lt;P&gt;The code&lt;/P&gt;
&lt;P&gt;%mend my_yearly_stuff;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;tells us two things, one it is the end of a macro definition and (if use properly) that the macro it is ending is my_yearly_stuff. If you have any text other than the macro it is ending you will get a warning in the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Better would be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%mend my_yearly_stuff;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%my_yearly_stuff;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2017 15:37:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/My-code-doesn-t-want-to-work-inside-a-DO-loop-not-accessing/m-p/393928#M94899</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-09-07T15:37:18Z</dc:date>
    </item>
  </channel>
</rss>

