<?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 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/loop/m-p/651277#M195392</link>
    <description>&lt;P&gt;First thing would be to provide an actual data step that shows the values that you currently have.&lt;/P&gt;
&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the &amp;lt;&amp;gt; icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code references an existing variable per_change. You do not actually show any existing value for "per_change". Do not name variables one thing and then show them with a different heading. If A is supposed to be per_change then the column heading should be Per_change &lt;STRONG&gt;or &lt;/STRONG&gt;your code should reference A instead of per_change.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS will without additional code to change flow perform all of the code statements for each record in the data. So you do not need to attempt to "force" the five example rows to calculate with the Do loop if that is what you think you are attempting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need the value calculated on one line of date to be kept for use on another then you use the RETAIN statement to indicate such use is intended for a variable. But you need to be a tad clearer about what you intend because it is not very clear at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 28 May 2020 04:18:52 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-05-28T04:18:52Z</dc:date>
    <item>
      <title>loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/loop/m-p/651250#M195379</link>
      <description>&lt;P&gt;hi I have data as below I am looking to create another variable using %change column and number starting number from column. then use output of that and next % change value to create new variable and so on.&amp;nbsp; the new index column is what I wanted to create using starting value from B and then % from column A.&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#ff0000"&gt;date&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;B&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new_index&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;&lt;STRONG&gt;30&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;-Sep-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;01&amp;nbsp; &lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;0.45&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;% &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;3500&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;62799.435&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;&lt;STRONG&gt;31&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;-Dec-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;02&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;1.02&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;% &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;2000&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;3484.320557&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;&lt;STRONG&gt;31&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;-Mar-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;04&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;0.58&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;% &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;4800&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;3449.139336&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;&lt;STRONG&gt;30&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;-Jun-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;05&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;0.93&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;% &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;5698&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;3429.249688&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;&lt;STRONG&gt;30&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;-Sep-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;06&amp;nbsp; &lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;0.74&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;% &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;5896&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;3397.651529&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data test_;
set Re_data;

do i= 1 to 5;

new_index=B/(1+per_change);

/*ouput of new_index then will become B and use next Per_change vallue*/


end;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 May 2020 00:20:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/loop/m-p/651250#M195379</guid>
      <dc:creator>SASUser0001</dc:creator>
      <dc:date>2020-05-28T00:20:27Z</dc:date>
    </item>
    <item>
      <title>Re: loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/loop/m-p/651253#M195380</link>
      <description>&lt;P&gt;I don't follow what you are trying to do.&amp;nbsp; Why does I go from 1 to 5?&amp;nbsp; What does I represent?&lt;/P&gt;
&lt;P&gt;Is the value of NEW_INDEX represent what you are trying to create from B?&amp;nbsp; If so I cannot see how the math will work out.&amp;nbsp; 62,799 is almost 18 times 3,500.&lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2020 01:06:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/loop/m-p/651253#M195380</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-05-28T01:06:14Z</dc:date>
    </item>
    <item>
      <title>Re: loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/loop/m-p/651277#M195392</link>
      <description>&lt;P&gt;First thing would be to provide an actual data step that shows the values that you currently have.&lt;/P&gt;
&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the &amp;lt;&amp;gt; icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code references an existing variable per_change. You do not actually show any existing value for "per_change". Do not name variables one thing and then show them with a different heading. If A is supposed to be per_change then the column heading should be Per_change &lt;STRONG&gt;or &lt;/STRONG&gt;your code should reference A instead of per_change.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS will without additional code to change flow perform all of the code statements for each record in the data. So you do not need to attempt to "force" the five example rows to calculate with the Do loop if that is what you think you are attempting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need the value calculated on one line of date to be kept for use on another then you use the RETAIN statement to indicate such use is intended for a variable. But you need to be a tad clearer about what you intend because it is not very clear at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2020 04:18:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/loop/m-p/651277#M195392</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-05-28T04:18:52Z</dc:date>
    </item>
    <item>
      <title>Re: loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/loop/m-p/651337#M195425</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/322738"&gt;@SASUser0001&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use the implied loop of the DATA step instead of an explicit DO loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input date :date. A :percent. B;
format date date11. A percent7.2;
cards;
30-Sep-01 0.45% 3500
31-Dec-02 1.02% 2000
31-Mar-04 0.58% 4800
30-Jun-05 0.93% 5698
30-Sep-06 0.74% 5896
;

data want;
set have;
retain new_index 62799.435;
output;
if _n_=1 then new_index=b;
new_index=new_index/(1+a);
format new_index best11.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 May 2020 09:18:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/loop/m-p/651337#M195425</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-05-28T09:18:46Z</dc:date>
    </item>
  </channel>
</rss>

