<?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: HELP!! Problem in using lag function in a Do-until statement in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/HELP-Problem-in-using-lag-function-in-a-Do-until-statement/m-p/122752#M33720</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, Art:&lt;/P&gt;&lt;P&gt;&amp;nbsp; I know there are exceptions. However, generally, I try to keep my suggestions at the same approximate skill level as the posted code. Given the fact that calling the LAG function inside the DO loop didn't seem appropriate and that the code was written in a way that there was NO idea what the input was or what the desired result was, I gave a link that (I hoped) would prompt further investigation into the basics of the LAG function. Then, after the basics are understood, that's the time for exceptions. (IMHO)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Thanks for the link.&lt;/P&gt;&lt;P&gt;cynthia&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 16 Sep 2012 17:14:24 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2012-09-16T17:14:24Z</dc:date>
    <item>
      <title>HELP!! Problem in using lag function in a Do-until statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/HELP-Problem-in-using-lag-function-in-a-Do-until-statement/m-p/122745#M33713</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I was trying to write a loop as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data ...;&lt;/P&gt;&lt;P&gt;set ...;&amp;nbsp;&amp;nbsp; (a variable called &lt;EM&gt;attendance&lt;/EM&gt; is included)&lt;/P&gt;&lt;P&gt;temp=1;&lt;/P&gt;&lt;P&gt;do until (temp=5);&lt;/P&gt;&lt;P&gt;prev_attend=lag(attendance);&lt;/P&gt;&lt;P&gt;if prev_attend=temp then attendance=prev_attend+1;&lt;/P&gt;&lt;P&gt;temp+1;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was hoping to have the prev_attend updated each time the loop starts again, however this does not seem possible? Any suggestions?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Sep 2012 09:55:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/HELP-Problem-in-using-lag-function-in-a-Do-until-statement/m-p/122745#M33713</guid>
      <dc:creator>RohanSmith</dc:creator>
      <dc:date>2012-09-15T09:55:05Z</dc:date>
    </item>
    <item>
      <title>Re: HELP!! Problem in using lag function in a Do-until statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/HELP-Problem-in-using-lag-function-in-a-Do-until-statement/m-p/122746#M33714</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Looking at the whole program, there is probably an easier way to accomplish your overall objective.&amp;nbsp; But since you only asked about incrementing prev_attend, here's a good way to do it.&amp;nbsp; It may or may not work, depending on what you are trying to assign to PREV_ATTEND.&amp;nbsp; This will get the final value of ATTENDANCE from the previous observation, after the DO loop has completed. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Remove this from the DO loop:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;prev_attend=lag(attendance);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ADD this statement BEFORE the SET statement:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;prev_attend=attendance;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That should be one way to handle it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you are looking to get the ORIGINAL value of ATTENDANCE, from BEFORE the DO loop started, then just place the LAG function OUTSIDE of the DO loop:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;prev_attend=lag(attendance);&lt;/P&gt;&lt;P&gt;do until (temp=5);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Sep 2012 15:46:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/HELP-Problem-in-using-lag-function-in-a-Do-until-statement/m-p/122746#M33714</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2012-09-15T15:46:19Z</dc:date>
    </item>
    <item>
      <title>Re: HELP!! Problem in using lag function in a Do-until statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/HELP-Problem-in-using-lag-function-in-a-Do-until-statement/m-p/122747#M33715</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It is not entirely clear what you want but it might be simply this :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;data ...;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;set ...;&amp;nbsp;&amp;nbsp; (a variable called attendance is included)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;prev_attend=lag(attendance);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;do temp = 1 to 5;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if prev_attend=temp then attendance=prev_attend+1;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Sep 2012 15:58:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/HELP-Problem-in-using-lag-function-in-a-Do-until-statement/m-p/122747#M33715</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2012-09-15T15:58:21Z</dc:date>
    </item>
    <item>
      <title>Re: HELP!! Problem in using lag function in a Do-until statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/HELP-Problem-in-using-lag-function-in-a-Do-until-statement/m-p/122748#M33716</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you provide a small sample dataset, in the form of a data step, as well as what you would want that dataset to look like after the code has been run?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Sep 2012 16:16:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/HELP-Problem-in-using-lag-function-in-a-Do-until-statement/m-p/122748#M33716</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-09-15T16:16:49Z</dc:date>
    </item>
    <item>
      <title>Re: HELP!! Problem in using lag function in a Do-until statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/HELP-Problem-in-using-lag-function-in-a-Do-until-statement/m-p/122749#M33717</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Hi:&lt;/P&gt;&lt;P&gt;&amp;nbsp; Read the comments in this Tech Support sample code carefully:&lt;/P&gt;&lt;P&gt;&lt;A class="active_link" href="http://support.sas.com/kb/24/665.html"&gt;http://support.sas.com/kb/24/665.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; The note contains an example of using the LAG function and in the program code, it says:&lt;/P&gt;&lt;P&gt;"Because the LAG function stores values on the queue only when it is called, you &lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;must&lt;/STRONG&gt;&lt;STRONG&gt; call LAG&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;unconditionally&lt;/STRONG&gt; &lt;EM&gt;&lt;STRONG&gt;(outside the IF condition)&lt;/STRONG&gt;&lt;/EM&gt;&lt;/SPAN&gt; &lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;to get the correct answers&lt;/STRONG&gt;&lt;/SPAN&gt;."&lt;/P&gt;&lt;P&gt;(emphasis mine)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cynthia&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Sep 2012 20:25:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/HELP-Problem-in-using-lag-function-in-a-Do-until-statement/m-p/122749#M33717</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2012-09-15T20:25:14Z</dc:date>
    </item>
    <item>
      <title>Re: HELP!! Problem in using lag function in a Do-until statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/HELP-Problem-in-using-lag-function-in-a-Do-until-statement/m-p/122750#M33718</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Cynthia:&amp;nbsp; The reason I asked Rohan to explain what he was looking for is that there are exceptions to that rule.&amp;nbsp; Take a look at: &lt;A href="http://www.sascommunity.org/wiki/Conditional_Use_of_LAG" title="http://www.sascommunity.org/wiki/Conditional_Use_of_LAG"&gt;http://www.sascommunity.org/wiki/Conditional_Use_of_LAG&lt;/A&gt; .&amp;nbsp; Additionally, he was calling it five times within the same record.&amp;nbsp; I, for one, have absolutely NO idea what he is expecting.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Sep 2012 21:16:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/HELP-Problem-in-using-lag-function-in-a-Do-until-statement/m-p/122750#M33718</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-09-15T21:16:37Z</dc:date>
    </item>
    <item>
      <title>Re: HELP!! Problem in using lag function in a Do-until statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/HELP-Problem-in-using-lag-function-in-a-Do-until-statement/m-p/122751#M33719</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The suggestions from Astounding worked for me. All comments here have been greatly appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 16 Sep 2012 01:34:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/HELP-Problem-in-using-lag-function-in-a-Do-until-statement/m-p/122751#M33719</guid>
      <dc:creator>RohanSmith</dc:creator>
      <dc:date>2012-09-16T01:34:17Z</dc:date>
    </item>
    <item>
      <title>Re: HELP!! Problem in using lag function in a Do-until statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/HELP-Problem-in-using-lag-function-in-a-Do-until-statement/m-p/122752#M33720</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, Art:&lt;/P&gt;&lt;P&gt;&amp;nbsp; I know there are exceptions. However, generally, I try to keep my suggestions at the same approximate skill level as the posted code. Given the fact that calling the LAG function inside the DO loop didn't seem appropriate and that the code was written in a way that there was NO idea what the input was or what the desired result was, I gave a link that (I hoped) would prompt further investigation into the basics of the LAG function. Then, after the basics are understood, that's the time for exceptions. (IMHO)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Thanks for the link.&lt;/P&gt;&lt;P&gt;cynthia&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 16 Sep 2012 17:14:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/HELP-Problem-in-using-lag-function-in-a-Do-until-statement/m-p/122752#M33720</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2012-09-16T17:14:24Z</dc:date>
    </item>
  </channel>
</rss>

