<?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: Learning SAS - would like some help understanding DO Loops in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Learning-SAS-would-like-some-help-understanding-DO-Loops/m-p/60315#M13036</link>
    <description>Hi KyleS83&lt;BR /&gt;
&lt;BR /&gt;
The documentation to start with for better understanding how SAS works is:&lt;BR /&gt;
SAS(R) 9.2 Language Reference: Concepts, Second Edition, &lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a002586295.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a002586295.htm&lt;/A&gt;&lt;BR /&gt;
You could read through section "Data Step Processing".&lt;BR /&gt;
&lt;BR /&gt;
If you want to take it a step further then this excellent paper from Paul Dorfman might be a good start: &lt;A href="http://support.sas.com/resources/papers/proceedings09/010-2009.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings09/010-2009.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Don't use the techniques Paul Dorfman describes before your SAS skills are on a very solid level.&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick</description>
    <pubDate>Sat, 30 Apr 2011 03:47:18 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2011-04-30T03:47:18Z</dc:date>
    <item>
      <title>Learning SAS - would like some help understanding DO Loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Learning-SAS-would-like-some-help-understanding-DO-Loops/m-p/60311#M13032</link>
      <description>Hi all, I'm currently learning Basic SAS and am trying to learn the mechanics of DO Loops. I have a simple code here but would like to understand how SAS would execute it. Here is the code:&lt;BR /&gt;
&lt;BR /&gt;
data balance;&lt;BR /&gt;
    bal=1000;&lt;BR /&gt;
    do i=1 to 12;&lt;BR /&gt;
       bal=bal*1.01;&lt;BR /&gt;
       output;&lt;BR /&gt;
       end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Although I do know what the result would be, I still have a few questions that I would like to ask that would better help me understand how SAS executes this loop.&lt;BR /&gt;
&lt;BR /&gt;
1. assume SAS is reading this for the first time and is on its first loop (i=1).  Since we're given that bal=1000 outside the DO Loop, how come IN the Do Loop, SAS will calculate it as bal = 1000*1.01 and not 1000 = 1000*10.1?  Shouldn't the variable be different say total=bal*1.01?&lt;BR /&gt;
&lt;BR /&gt;
2. so after SAS goes through the loop once, the balance after 1000 is multiplied by 1.01 and gives 1010, so how does SAS memorize the 1010 for the 2nd loop execution and multiply that by 1.01? Does SAS change the bal=1000 outside the DO Loop to bal=1010?  If not, then how is SAS able to memorize the result from the previous loop and carry it into the next loop for calculation?&lt;BR /&gt;
&lt;BR /&gt;
Hope my questions are not confusing...thanks!</description>
      <pubDate>Fri, 29 Apr 2011 21:24:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Learning-SAS-would-like-some-help-understanding-DO-Loops/m-p/60311#M13032</guid>
      <dc:creator>KyleS83</dc:creator>
      <dc:date>2011-04-29T21:24:19Z</dc:date>
    </item>
    <item>
      <title>Re: Learning SAS - would like some help understanding DO Loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Learning-SAS-would-like-some-help-understanding-DO-Loops/m-p/60312#M13033</link>
      <description>&amp;gt; Hi all, I'm currently learning Basic SAS and am&lt;BR /&gt;
&amp;gt; trying to learn the mechanics of DO Loops. I have a&lt;BR /&gt;
&amp;gt; simple code here but would like to understand how SAS&lt;BR /&gt;
&amp;gt; would execute it. Here is the code:&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; data balance;&lt;BR /&gt;
&amp;gt;     bal=1000;&lt;BR /&gt;
&amp;gt; do i=1 to 12;&lt;BR /&gt;
&amp;gt;        bal=bal*1.01;&lt;BR /&gt;
&amp;gt; output;&lt;BR /&gt;
&amp;gt;        end;&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Although I do know what the result would be, I still&lt;BR /&gt;
&amp;gt; have a few questions that I would like to ask that&lt;BR /&gt;
&amp;gt; would better help me understand how SAS executes this&lt;BR /&gt;
&amp;gt; loop.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; 1. assume SAS is reading this for the first time and&lt;BR /&gt;
&amp;gt; is on its first loop (i=1).  Since we're given that&lt;BR /&gt;
&amp;gt; bal=1000 outside the DO Loop, how come IN the Do&lt;BR /&gt;
&amp;gt; Loop, SAS will calculate it as bal = 1000*1.01 and&lt;BR /&gt;
&amp;gt; not 1000 = 1000*10.1?  Shouldn't the variable be&lt;BR /&gt;
&amp;gt; different say total=bal*1.01?&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&lt;BR /&gt;
Things on the LEFT side of a = sign are where results go (generally, there are exceptions but don't apply to this example). So BAL= in effect says "do what's on the right side of the equal sign and store the result in a place named BAL. If BAL already has a value it will be replaced. If you don't want to replace the value then don't. In your example of TOTAL=BAL*10.1; however you would get the exact same value for TOTAL. My take on the original code is someone wants to look at something like compound interest applying 1% successively.&lt;BR /&gt;
&lt;BR /&gt;
Try this code to see what's happenng.&lt;BR /&gt;
&lt;BR /&gt;
 PROC Print data=balance; run;&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; 2. so after SAS goes through the loop once, the&lt;BR /&gt;
&amp;gt; balance after 1000 is multiplied by 1.01 and gives&lt;BR /&gt;
&amp;gt; 1010, so how does SAS memorize the 1010 for the 2nd&lt;BR /&gt;
&amp;gt; loop execution and multiply that by 1.01? Does SAS&lt;BR /&gt;
&amp;gt; change the bal=1000 outside the DO Loop to bal=1010?&lt;BR /&gt;
&amp;gt; If not, then how is SAS able to memorize the result&lt;BR /&gt;
&amp;gt; from the previous loop and carry it into the next&lt;BR /&gt;
&amp;gt;  loop for calculation?&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Hope my questions are not confusing...thanks!&lt;BR /&gt;
&lt;BR /&gt;
Conceptually  BAL is a single storage bucket that only ever contains one value at a time within a single data step.</description>
      <pubDate>Fri, 29 Apr 2011 21:49:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Learning-SAS-would-like-some-help-understanding-DO-Loops/m-p/60312#M13033</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2011-04-29T21:49:26Z</dc:date>
    </item>
    <item>
      <title>Re: Learning SAS - would like some help understanding DO Loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Learning-SAS-would-like-some-help-understanding-DO-Loops/m-p/60313#M13034</link>
      <description>Kyle,&lt;BR /&gt;
&lt;BR /&gt;
I think you are asking "what does the program data vector (PDV) see?"&lt;BR /&gt;
&lt;BR /&gt;
If so, just add some put _all_ statements in your code.  E.g.,&lt;BR /&gt;
[pre]&lt;BR /&gt;
data balance;&lt;BR /&gt;
  bal=1000;&lt;BR /&gt;
  put _all_;&lt;BR /&gt;
  do i=1 to 12;&lt;BR /&gt;
    put _all_;&lt;BR /&gt;
    bal=bal*1.01;&lt;BR /&gt;
    put _all_;&lt;BR /&gt;
    output;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
HTH,&lt;BR /&gt;
Art</description>
      <pubDate>Fri, 29 Apr 2011 22:40:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Learning-SAS-would-like-some-help-understanding-DO-Loops/m-p/60313#M13034</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-04-29T22:40:42Z</dc:date>
    </item>
    <item>
      <title>Re: Learning SAS - would like some help understanding DO Loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Learning-SAS-would-like-some-help-understanding-DO-Loops/m-p/60314#M13035</link>
      <description>thanks for the input, it definitely helped me understand it more.  Any other explanations would be greatly appreciated as well...Thanks!</description>
      <pubDate>Fri, 29 Apr 2011 22:59:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Learning-SAS-would-like-some-help-understanding-DO-Loops/m-p/60314#M13035</guid>
      <dc:creator>KyleS83</dc:creator>
      <dc:date>2011-04-29T22:59:26Z</dc:date>
    </item>
    <item>
      <title>Re: Learning SAS - would like some help understanding DO Loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Learning-SAS-would-like-some-help-understanding-DO-Loops/m-p/60315#M13036</link>
      <description>Hi KyleS83&lt;BR /&gt;
&lt;BR /&gt;
The documentation to start with for better understanding how SAS works is:&lt;BR /&gt;
SAS(R) 9.2 Language Reference: Concepts, Second Edition, &lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a002586295.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a002586295.htm&lt;/A&gt;&lt;BR /&gt;
You could read through section "Data Step Processing".&lt;BR /&gt;
&lt;BR /&gt;
If you want to take it a step further then this excellent paper from Paul Dorfman might be a good start: &lt;A href="http://support.sas.com/resources/papers/proceedings09/010-2009.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings09/010-2009.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Don't use the techniques Paul Dorfman describes before your SAS skills are on a very solid level.&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick</description>
      <pubDate>Sat, 30 Apr 2011 03:47:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Learning-SAS-would-like-some-help-understanding-DO-Loops/m-p/60315#M13036</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2011-04-30T03:47:18Z</dc:date>
    </item>
  </channel>
</rss>

