<?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: Explain do loops in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Explain-do-loops/m-p/231103#M42007</link>
    <description>&lt;P&gt;Thanks for your help. The explanation was very simplified and clear&lt;/P&gt;</description>
    <pubDate>Thu, 22 Oct 2015 10:35:30 GMT</pubDate>
    <dc:creator>vatemro</dc:creator>
    <dc:date>2015-10-22T10:35:30Z</dc:date>
    <item>
      <title>Explain do loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Explain-do-loops/m-p/231096#M42003</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please can someone explain in details the data steps below and what each data statement is doing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data work.invest;&lt;/P&gt;&lt;P&gt;do year = 2010 to 2014;&lt;/P&gt;&lt;P&gt;capital + 3000;&lt;/P&gt;&lt;P&gt;capital + (capital * 0.10);&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Oct 2015 10:08:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Explain-do-loops/m-p/231096#M42003</guid>
      <dc:creator>vatemro</dc:creator>
      <dc:date>2015-10-22T10:08:05Z</dc:date>
    </item>
    <item>
      <title>Re: Explain do loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Explain-do-loops/m-p/231100#M42004</link>
      <description>&lt;P&gt;The do loop repeats the code within the block the number of times specified by the from and to (and step if supplied).&lt;/P&gt;
&lt;P&gt;data work.invest;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; do year = 2010 to 2014;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; capital + 3000;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; capital + (capital * 0.10);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;In your instance, the loop variable year runs from 2010 to 2014 (default step 1), so 2010, 2011, 2012, 2013.&lt;/P&gt;
&lt;P&gt;You can expand the code to look like:&lt;/P&gt;
&lt;P&gt;year=2010&lt;/P&gt;
&lt;P&gt;add 3000 to capital&lt;/P&gt;
&lt;P&gt;add capital multiplied by 0.10 to capital&lt;/P&gt;
&lt;P&gt;year=2011&lt;/P&gt;
&lt;P&gt;add 3000 to capital&lt;/P&gt;
&lt;P&gt;add capital multiplied by 0.10 to capital&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So year will end up as 2014, and capital will be the end result of those adds.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Oct 2015 10:23:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Explain-do-loops/m-p/231100#M42004</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-10-22T10:23:51Z</dc:date>
    </item>
    <item>
      <title>Re: Explain do loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Explain-do-loops/m-p/231101#M42005</link>
      <description>&lt;P&gt;Is this an interview or study question?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you know SAS Language at all? Which bit of the code is not clear to you?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here the documentation for a do-loop:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/documentation/cdl/en/lestmtsref/68024/HTML/default/viewer.htm#p1cydk5fq0u4bfn1xfbjt7w1c7lu.htm" target="_blank"&gt;https://support.sas.com/documentation/cdl/en/lestmtsref/68024/HTML/default/viewer.htm#p1cydk5fq0u4bfn1xfbjt7w1c7lu.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another good way to understand what's happening is to actually execute the code, look at the result and try to understand what's going on. Each "output" statement in below code will write a row to table "work.invest".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.invest;
  do year = 2010 to 2014;
    output;
    capital + 3000;
    output;
    capital + (capital * 0.10);
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Oct 2015 10:26:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Explain-do-loops/m-p/231101#M42005</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-10-22T10:26:56Z</dc:date>
    </item>
    <item>
      <title>Re: Explain do loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Explain-do-loops/m-p/231102#M42006</link>
      <description>&lt;P&gt;Am new to programming and am not sure about a lot of the statements. Thanks for your help&lt;/P&gt;</description>
      <pubDate>Thu, 22 Oct 2015 10:34:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Explain-do-loops/m-p/231102#M42006</guid>
      <dc:creator>vatemro</dc:creator>
      <dc:date>2015-10-22T10:34:27Z</dc:date>
    </item>
    <item>
      <title>Re: Explain do loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Explain-do-loops/m-p/231103#M42007</link>
      <description>&lt;P&gt;Thanks for your help. The explanation was very simplified and clear&lt;/P&gt;</description>
      <pubDate>Thu, 22 Oct 2015 10:35:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Explain-do-loops/m-p/231103#M42007</guid>
      <dc:creator>vatemro</dc:creator>
      <dc:date>2015-10-22T10:35:30Z</dc:date>
    </item>
  </channel>
</rss>

