<?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: Do loop understand in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-understand/m-p/337771#M76774</link>
    <description>&lt;P&gt;When you see the&amp;nbsp;&lt;STRONG&gt;%&lt;/STRONG&gt; as part of the code (like: %do, %to, %macro, %mend, %if etc.)&lt;/P&gt;
&lt;P&gt;the code is part of a &lt;U&gt;macro program&lt;/U&gt;. A macro program is a kind of program generator.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code you are looking at includes, probably, next lines:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;$macro &amp;lt;macro_name&amp;gt; (argument1, argument2,...); /* start definition of a macro program */
     .....
    %do i=1 %to 60 %by 1;
          %do j=&amp;amp;i-1 %to &amp;amp;i-1;
                 ...... more code lines ...
          %end;   /* ending inner loop */
    %end;        /* ending outer loop */
    ..........
%mend &amp;lt;macro_name&amp;gt;; /* ending definition of a macro program */
%macro_name(...arguments...); /* execution of the macro program */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;so, the two lines you showd is actaullay producing similar code, again and agian, with slight modification&lt;/P&gt;
&lt;P&gt;according to i counting from 1 to 60 (are there 60 segemnet or variables ?), maybe relating to the previous one (as j=&amp;amp;i-1);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;i&lt;/STRONG&gt; and &lt;STRONG&gt;j&lt;/STRONG&gt; in this case, in a macro program, are called &lt;U&gt;macro variables&lt;/U&gt;. You relate to macro variable by adding prefix &amp;amp; before the name, that is: &amp;amp;i, &amp;amp;j etc.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 03 Mar 2017 10:30:21 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2017-03-03T10:30:21Z</dc:date>
    <item>
      <title>Do loop understand</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-understand/m-p/337762#M76767</link>
      <description>&lt;P&gt;Hi Guys ,&lt;/P&gt;&lt;P&gt;I'm new to sas programming and now im trying to understand the sas program wriiten by someone -&lt;/P&gt;&lt;P&gt;can you please give me idea how below statment works ?&lt;BR /&gt;&lt;BR /&gt;%do i=1 %to 60 %by 1;&lt;/P&gt;&lt;P&gt;%do j=&amp;amp;i-1 %to &amp;amp;i-1;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2017 10:01:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-understand/m-p/337762#M76767</guid>
      <dc:creator>mahinikam</dc:creator>
      <dc:date>2017-03-03T10:01:01Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop understand</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-understand/m-p/337765#M76769</link>
      <description>&lt;P&gt;First of all, this is not a do loop, it is a %do loop, a very important distinction.&lt;/P&gt;
&lt;P&gt;%do means this is a macro statement, and it is executed by the macro preprocessor, and is used to create dynamic SAS code.&lt;/P&gt;
&lt;P&gt;(think of the C preprocessor, if you are familiar with programming and the C language)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do i=1 %to 60 %by 1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will create a macro variable i (later to be referenced by &amp;amp;i), assigns it the value 1, execute what is inside the block up to %end;, increase i by 1 and repeat until i exceeds 60&lt;/P&gt;
&lt;P&gt;Similarly,&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do j=&amp;amp;i-1 %to &amp;amp;i-1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will iterate from i-1 to i-1, so it will do only one iteration.&lt;/P&gt;
&lt;P&gt;Caution: the macro preprocessor knows only one datatype, namely text. That the calculation &amp;amp;i-1 is possible is a capability of the iterative %do macro statement, usually one would need to use %eval(&amp;amp;i-1) to do calculations with macro variables.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2017 10:15:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-understand/m-p/337765#M76769</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-03-03T10:15:11Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop understand</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-understand/m-p/337771#M76774</link>
      <description>&lt;P&gt;When you see the&amp;nbsp;&lt;STRONG&gt;%&lt;/STRONG&gt; as part of the code (like: %do, %to, %macro, %mend, %if etc.)&lt;/P&gt;
&lt;P&gt;the code is part of a &lt;U&gt;macro program&lt;/U&gt;. A macro program is a kind of program generator.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code you are looking at includes, probably, next lines:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;$macro &amp;lt;macro_name&amp;gt; (argument1, argument2,...); /* start definition of a macro program */
     .....
    %do i=1 %to 60 %by 1;
          %do j=&amp;amp;i-1 %to &amp;amp;i-1;
                 ...... more code lines ...
          %end;   /* ending inner loop */
    %end;        /* ending outer loop */
    ..........
%mend &amp;lt;macro_name&amp;gt;; /* ending definition of a macro program */
%macro_name(...arguments...); /* execution of the macro program */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;so, the two lines you showd is actaullay producing similar code, again and agian, with slight modification&lt;/P&gt;
&lt;P&gt;according to i counting from 1 to 60 (are there 60 segemnet or variables ?), maybe relating to the previous one (as j=&amp;amp;i-1);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;i&lt;/STRONG&gt; and &lt;STRONG&gt;j&lt;/STRONG&gt; in this case, in a macro program, are called &lt;U&gt;macro variables&lt;/U&gt;. You relate to macro variable by adding prefix &amp;amp; before the name, that is: &amp;amp;i, &amp;amp;j etc.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2017 10:30:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-understand/m-p/337771#M76774</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-03-03T10:30:21Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop understand</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-understand/m-p/337779#M76778</link>
      <description>&lt;P&gt;The second loop&lt;/P&gt;
&lt;DIV class="lia-quilt-row lia-quilt-row-forum-message-main"&gt;
&lt;DIV class="lia-quilt-column lia-quilt-column-20 lia-quilt-column-right lia-quilt-column-main-right"&gt;
&lt;DIV class="lia-quilt-column-alley lia-quilt-column-alley-right"&gt;
&lt;DIV id="messagebodydisplay_0" class="lia-message-body"&gt;
&lt;DIV class="lia-message-body-content"&gt;
&lt;P&gt;%do j=&amp;amp;i-1 %to &amp;amp;i-1; &lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;seems rather useless as it only performs one iteration.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It could be replaced by a simple affectation :&lt;/P&gt;
&lt;P&gt;%let j=&amp;amp;i.-1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let j=%eval(&amp;amp;i.-1)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The difference between both commands is that, with the first, whenever &amp;amp;j. is encountered in&lt;/P&gt;
&lt;P&gt;the program, there will only be a subtitution for the current value of i and no evaluation of&lt;/P&gt;
&lt;P&gt;the resulting expression, e.g., if &amp;amp;i.=10, &amp;amp;j. will be replaced by 10-1 wich may not be what we want&lt;/P&gt;
&lt;P&gt;in certain contexts. Using %eval will ensure that the resulting expression will be evaluated so that&lt;/P&gt;
&lt;P&gt;each occurrence of &amp;amp;j will be replaced by the value of &amp;amp;i.-1 (9 in the example).&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2017 10:59:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-understand/m-p/337779#M76778</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2017-03-03T10:59:19Z</dc:date>
    </item>
  </channel>
</rss>

