<?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: how to write a loop for this data structure in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-loop-for-this-data-structure/m-p/614402#M179592</link>
    <description>&lt;P&gt;First of all, forget your Excel thinking. It will only hinder your SAS growth. SAS has observations (records or rows), and columns that have the same name in&amp;nbsp;&lt;EM&gt;all&lt;/EM&gt; observations. There are no "cells",&lt;/P&gt;
&lt;P&gt;See this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
b = ifn(_n_ = 1,b,lag(b) - lag(a) / 224);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The ifn() function is necessary to keep b in the first observation, while still executing the lag() functions.&lt;/P&gt;
&lt;P&gt;See if the code works for you, and try to understand it. Come back with any questions you have.&lt;/P&gt;</description>
    <pubDate>Mon, 30 Dec 2019 15:15:56 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-12-30T15:15:56Z</dc:date>
    <item>
      <title>how to write a loop for this data structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-loop-for-this-data-structure/m-p/614392#M179582</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;As in the attachment (part of my data), my data has two columns, the total number of column A is 224. Numbers in column is calculated as following:&lt;/P&gt;&lt;P&gt;B2=B1-A1/224&lt;/P&gt;&lt;P&gt;B3=B2-A2/224&lt;/P&gt;&lt;P&gt;B4=B3-A3/224&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;Could anyone help me how to write a loop in SAS to do this calculation.&lt;/P&gt;&lt;P&gt;thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2019 14:19:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-loop-for-this-data-structure/m-p/614392#M179582</guid>
      <dc:creator>superbug</dc:creator>
      <dc:date>2019-12-30T14:19:39Z</dc:date>
    </item>
    <item>
      <title>Re: how to write a loop for this data structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-loop-for-this-data-structure/m-p/614393#M179583</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/304931"&gt;@superbug&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you please provide some sample data to play with?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2019 14:24:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-loop-for-this-data-structure/m-p/614393#M179583</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2019-12-30T14:24:01Z</dc:date>
    </item>
    <item>
      <title>Re: how to write a loop for this data structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-loop-for-this-data-structure/m-p/614394#M179584</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097"&gt;@ed_sas_member&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here is what my data look like, total number of column A is 224&lt;/P&gt;&lt;P&gt;&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;B&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 15&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.933&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.9286&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.9241&lt;/P&gt;&lt;P&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.9196&lt;/P&gt;&lt;P&gt;6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.9152&lt;/P&gt;&lt;P&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; .&lt;/P&gt;&lt;P&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; .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you!!&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2019 14:28:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-loop-for-this-data-structure/m-p/614394#M179584</guid>
      <dc:creator>superbug</dc:creator>
      <dc:date>2019-12-30T14:28:55Z</dc:date>
    </item>
    <item>
      <title>Re: how to write a loop for this data structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-loop-for-this-data-structure/m-p/614396#M179586</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/304931"&gt;@superbug&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;As in the attachment (part of my data), my data has two columns, the total number of column A is 224. Numbers in column is calculated as following:&lt;/P&gt;
&lt;P&gt;B2=B1-A1/224&lt;/P&gt;
&lt;P&gt;B3=B2-A2/224&lt;/P&gt;
&lt;P&gt;B4=B3-A3/224&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;Could anyone help me how to write a loop in SAS to do this calculation.&lt;/P&gt;
&lt;P&gt;thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Are these formulas like you would use in Excel??&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The only way to make use of Excel style programming logic in SAS is to start over and re-formulate the problem in SAS programming logic, and probably re-format the data to work smoothly in SAS, as the two programming paradigms are generally are not compatible.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2019 14:36:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-loop-for-this-data-structure/m-p/614396#M179586</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-12-30T14:36:23Z</dc:date>
    </item>
    <item>
      <title>Re: how to write a loop for this data structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-loop-for-this-data-structure/m-p/614398#M179588</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I only have column A data. I need to write SAS code using the above formula to get values in column B.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2019 14:48:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-loop-for-this-data-structure/m-p/614398#M179588</guid>
      <dc:creator>superbug</dc:creator>
      <dc:date>2019-12-30T14:48:46Z</dc:date>
    </item>
    <item>
      <title>Re: how to write a loop for this data structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-loop-for-this-data-structure/m-p/614402#M179592</link>
      <description>&lt;P&gt;First of all, forget your Excel thinking. It will only hinder your SAS growth. SAS has observations (records or rows), and columns that have the same name in&amp;nbsp;&lt;EM&gt;all&lt;/EM&gt; observations. There are no "cells",&lt;/P&gt;
&lt;P&gt;See this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
b = ifn(_n_ = 1,b,lag(b) - lag(a) / 224);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The ifn() function is necessary to keep b in the first observation, while still executing the lag() functions.&lt;/P&gt;
&lt;P&gt;See if the code works for you, and try to understand it. Come back with any questions you have.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2019 15:15:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-loop-for-this-data-structure/m-p/614402#M179592</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-12-30T15:15:56Z</dc:date>
    </item>
    <item>
      <title>Re: how to write a loop for this data structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-loop-for-this-data-structure/m-p/614408#M179596</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you!&lt;/P&gt;&lt;P&gt;using the code you provided, in the second column, I can only get the desired first two values, while the rest values in the second column are all missing. Here is what the result data look like. Please help me to revise the code to get all desired values in the second column.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;15&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.9330357&lt;/P&gt;&lt;P&gt;&amp;nbsp;1&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;1&lt;/P&gt;&lt;P&gt;&amp;nbsp;1&lt;/P&gt;&lt;P&gt;thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2019 15:49:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-loop-for-this-data-structure/m-p/614408#M179596</guid>
      <dc:creator>superbug</dc:creator>
      <dc:date>2019-12-30T15:49:06Z</dc:date>
    </item>
    <item>
      <title>Re: how to write a loop for this data structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-loop-for-this-data-structure/m-p/614413#M179600</link>
      <description>&lt;P&gt;Can't be.&lt;/P&gt;
&lt;P&gt;Code (including source data):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input a b;
datalines;
15 1
1 0.933
1 0.9286
1 0.9241
1 0.9196
2 0.9152
;

data want;
set have;
b = ifn(_n_ = 1,b,lag(b) - lag(a) / 224);
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;a	b
15	1.00000
1	0.93304
1	0.92854
1	0.92414
1	0.91964
2	0.91514&lt;/PRE&gt;</description>
      <pubDate>Mon, 30 Dec 2019 16:14:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-loop-for-this-data-structure/m-p/614413#M179600</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-12-30T16:14:56Z</dc:date>
    </item>
    <item>
      <title>Re: how to write a loop for this data structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-loop-for-this-data-structure/m-p/614428#M179610</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you! If there are values in b column, the code did work.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My case is there's value for the first row of column b&lt;/STRONG&gt;, I need to get all values of column b using information from column a. My data looks like the following&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;a      b    &lt;BR /&gt;15     1
1 
1 
1 
1 
2 &lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Total number of column a is 224. Using the code you suggested, I can only get the second number of b, which is 0.933. If I want to get the third number of column b, I have to use the information from "want" data, as following&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; want1&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; want&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
b &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;ifn&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;_n_ &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;b&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;lag&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;b&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;-&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;lag&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;a&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;/&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;224&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If I want to get the fourth number of column b, I have to use the information from "want1" data. Since my data has thousands of rows, to do this kind of repetition is impossible. For my specific case, please help with quick efficient ways.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you!!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2019 17:20:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-loop-for-this-data-structure/m-p/614428#M179610</guid>
      <dc:creator>superbug</dc:creator>
      <dc:date>2019-12-30T17:20:27Z</dc:date>
    </item>
    <item>
      <title>Re: how to write a loop for this data structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-loop-for-this-data-structure/m-p/614431#M179612</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;oops, it seems the data structure changed after I post it. It look like this&lt;/P&gt;&lt;P&gt;a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; b&lt;/P&gt;&lt;P&gt;15&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2019 17:30:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-loop-for-this-data-structure/m-p/614431#M179612</guid>
      <dc:creator>superbug</dc:creator>
      <dc:date>2019-12-30T17:30:01Z</dc:date>
    </item>
    <item>
      <title>Re: how to write a loop for this data structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-loop-for-this-data-structure/m-p/614432#M179613</link>
      <description>&lt;P&gt;Please post example data in a&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;working&amp;nbsp;&lt;/EM&gt;&lt;/STRONG&gt;&lt;STRONG&gt;data step with datalines&lt;/STRONG&gt;, as I did. That removes all ambiguities.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2019 17:30:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-loop-for-this-data-structure/m-p/614432#M179613</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-12-30T17:30:40Z</dc:date>
    </item>
    <item>
      <title>Re: how to write a loop for this data structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-loop-for-this-data-structure/m-p/614434#M179614</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my data look like the following&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input a&amp;nbsp; &amp;nbsp; b;&lt;BR /&gt;datalines;&lt;BR /&gt;15&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;BR /&gt;1&lt;BR /&gt;1&lt;BR /&gt;1&lt;BR /&gt;1&lt;BR /&gt;2&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you noticed, there is only value in the first row of variable b, I need to get all values of variable b. Using the following code, I can only get the second value of variable b.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;b=ifn(_n_=1, b, lag(b)-lag(a)/224);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;please help with how to get all values of variable b.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you so much!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2019 17:36:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-loop-for-this-data-structure/m-p/614434#M179614</guid>
      <dc:creator>superbug</dc:creator>
      <dc:date>2019-12-30T17:36:37Z</dc:date>
    </item>
    <item>
      <title>Re: how to write a loop for this data structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-loop-for-this-data-structure/m-p/614438#M179616</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/304931"&gt;@superbug&lt;/a&gt;&amp;nbsp; Your revised sample is a case for RETAIN statement. The following is a way to conveniently approach it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;_IORC_ is an automatic variable that is freely available and retains without needing a specify in Retain statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data have;
infile cards truncover;
input a    b;
datalines;
15         1
1
1
1
1
2
;

data want;
 set have;
  b=ifn(_n_=1, b, _iorc_-lag(a)/224);
 _iorc_=b;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Offer the credit to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp; and mark his solution as correct as the logic is still his idea with a tweak. Cheers!&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2019 18:10:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-loop-for-this-data-structure/m-p/614438#M179616</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-12-30T18:10:05Z</dc:date>
    </item>
    <item>
      <title>Re: how to write a loop for this data structure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-loop-for-this-data-structure/m-p/614443#M179619</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp; &amp;nbsp;Awesome, it worked! Thank you!!!&lt;/P&gt;&lt;P&gt;And thanks to you all for the help.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2019 18:26:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-write-a-loop-for-this-data-structure/m-p/614443#M179619</guid>
      <dc:creator>superbug</dc:creator>
      <dc:date>2019-12-30T18:26:32Z</dc:date>
    </item>
  </channel>
</rss>

