<?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: data step read calculated value of row in next row in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/data-step-read-calculated-value-of-row-in-next-row/m-p/528577#M144285</link>
    <description>&lt;P&gt;slick!!!!!!!!!!!!!!!!!!!!Kudos!&lt;/P&gt;</description>
    <pubDate>Sat, 19 Jan 2019 22:53:46 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-01-19T22:53:46Z</dc:date>
    <item>
      <title>data step read calculated value of row in next row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-read-calculated-value-of-row-in-next-row/m-p/528558#M144275</link>
      <description>&lt;P&gt;Input Table&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Input Table" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/26379i622B92CBF79DF534/image-size/large?v=v2&amp;amp;px=999" role="button" title="Input.PNG" alt="Input Table" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Input Table&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Desired output-&lt;STRONG&gt;Pred_lvl&lt;/STRONG&gt; col&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="output table" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/26380i3067530911465BF6/image-size/large?v=v2&amp;amp;px=999" role="button" title="desired output.PNG" alt="output table" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;output table&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But when I run Below code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;                                 
set Pred_level;                   
tes=lag4(pred_lvl);
if missing(pred_lvl) then pred_lvl = pred + tes; 
drop tes;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I am getting an output as below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="incorrect output table" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/26381i48DB9336BC711243/image-size/large?v=v2&amp;amp;px=999" role="button" title="myoutputwhich_is_incorrect.PNG" alt="incorrect output table" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;incorrect output table&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Problem:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;When I run my code it is only updating first 4 missing rows and remaining are still missing.&lt;/P&gt;&lt;P&gt;I need a code where&amp;nbsp;&lt;/P&gt;&lt;P&gt;if pred_lvl is missing pred_lvl= pred + lag4(pred_lvl);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The desired out put should be when ever pred_lvl is missing it should &lt;STRONG&gt;update&lt;/STRONG&gt; pred_lvl column by adding pred and pred_lvl[i-4]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;any help is much appreciated&lt;/P&gt;</description>
      <pubDate>Sat, 19 Jan 2019 19:42:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-read-calculated-value-of-row-in-next-row/m-p/528558#M144275</guid>
      <dc:creator>sidpesar</dc:creator>
      <dc:date>2019-01-19T19:42:59Z</dc:date>
    </item>
    <item>
      <title>Re: data step read calculated value of row in next row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-read-calculated-value-of-row-in-next-row/m-p/528560#M144276</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/182165"&gt;@sidpesar&lt;/a&gt;&amp;nbsp; Can you attach your input file or something that is transferable rather than pics?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And of course, explain the requirement aka business logic&lt;/P&gt;</description>
      <pubDate>Sat, 19 Jan 2019 19:37:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-read-calculated-value-of-row-in-next-row/m-p/528560#M144276</guid>
      <dc:creator>Andygray</dc:creator>
      <dc:date>2019-01-19T19:37:02Z</dc:date>
    </item>
    <item>
      <title>Re: data step read calculated value of row in next row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-read-calculated-value-of-row-in-next-row/m-p/528561#M144277</link>
      <description>&lt;P&gt;I added input csv file. Please let me know if you could figure it out. It will be very helpful&lt;/P&gt;</description>
      <pubDate>Sat, 19 Jan 2019 19:44:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-read-calculated-value-of-row-in-next-row/m-p/528561#M144277</guid>
      <dc:creator>sidpesar</dc:creator>
      <dc:date>2019-01-19T19:44:03Z</dc:date>
    </item>
    <item>
      <title>Re: data step read calculated value of row in next row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-read-calculated-value-of-row-in-next-row/m-p/528562#M144278</link>
      <description>&lt;P&gt;Are you looking to do this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;                                 
set Pred_level;   
retain tes; 
tes=ifn(pred_lvl&amp;gt;.,lag4(pred_lvl),tes);
if missing(pred_lvl) then pred_lvl = pred + tes; 
drop tes;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 19 Jan 2019 19:54:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-read-calculated-value-of-row-in-next-row/m-p/528562#M144278</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-01-19T19:54:44Z</dc:date>
    </item>
    <item>
      <title>Re: data step read calculated value of row in next row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-read-calculated-value-of-row-in-next-row/m-p/528563#M144279</link>
      <description>Thanks for quick reply the calulation is still wrong from 13th row again. Actual out put should be 0.06103576 but when I run below code I am getting 0.0612312338</description>
      <pubDate>Sat, 19 Jan 2019 19:59:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-read-calculated-value-of-row-in-next-row/m-p/528563#M144279</guid>
      <dc:creator>sidpesar</dc:creator>
      <dc:date>2019-01-19T19:59:07Z</dc:date>
    </item>
    <item>
      <title>Re: data step read calculated value of row in next row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-read-calculated-value-of-row-in-next-row/m-p/528564#M144280</link>
      <description>&lt;P&gt;Ok sorry I haven't tested. let me try&lt;/P&gt;</description>
      <pubDate>Sat, 19 Jan 2019 19:59:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-read-calculated-value-of-row-in-next-row/m-p/528564#M144280</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-01-19T19:59:53Z</dc:date>
    </item>
    <item>
      <title>Re: data step read calculated value of row in next row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-read-calculated-value-of-row-in-next-row/m-p/528572#M144283</link>
      <description>&lt;P&gt;Hio&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/182165"&gt;@sidpesar&lt;/a&gt;&amp;nbsp;Sorry for the delay as I had some personal stuff to do. The problem is the executed lag of source variable is not held in memory and so the real value missing is output from the 17 record onwards. The control of this can be dealt by assigning into a temp var from pred_lvl but I would leave that to MKeintz(lag specialist ) or somebody else to play with lag.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I prefer to control using array and to me this approach is so simple. See if this works until Mark the lag specialist&amp;nbsp; chimes in&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
do _n_=1 by 1 until(last.modelid);
set have;
by modelid;
array t(9999);
if pred_lvl&amp;gt;. then t(_n_)=pred_lvl;
else do; pred_lvl=t(_n_-4)+pred;t(_n_)=pred_lvl;end;
output;
end;
drop t:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 19 Jan 2019 21:45:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-read-calculated-value-of-row-in-next-row/m-p/528572#M144283</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-01-19T21:45:48Z</dc:date>
    </item>
    <item>
      <title>Re: data step read calculated value of row in next row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-read-calculated-value-of-row-in-next-row/m-p/528574#M144284</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/182165"&gt;@sidpesar&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you can also use a slightly modified version of your code (change the order of the assignment and IF/THEN statements and replace LAG4&amp;nbsp;with LAG3), combined with the RETAIN statement that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;suggested:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set Pred_level;
retain tes;
if missing(pred_lvl) then pred_lvl = pred + tes;
tes=lag3(pred_lvl);
drop tes;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 19 Jan 2019 22:33:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-read-calculated-value-of-row-in-next-row/m-p/528574#M144284</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-01-19T22:33:08Z</dc:date>
    </item>
    <item>
      <title>Re: data step read calculated value of row in next row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-read-calculated-value-of-row-in-next-row/m-p/528577#M144285</link>
      <description>&lt;P&gt;slick!!!!!!!!!!!!!!!!!!!!Kudos!&lt;/P&gt;</description>
      <pubDate>Sat, 19 Jan 2019 22:53:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-read-calculated-value-of-row-in-next-row/m-p/528577#M144285</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-01-19T22:53:46Z</dc:date>
    </item>
  </channel>
</rss>

