<?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 execution in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18222#M2713</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You also have trouble with the location of your LAG function calls in the first case.&amp;nbsp; You have placed if BEFORE the SET statement.&lt;/P&gt;&lt;P&gt;This pushes an extra set of missing values onto the stack so that you end up getting the value from two observations before the call.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code"&gt;&lt;P&gt;516&amp;nbsp; data test2;&lt;/P&gt;&lt;P&gt;517&amp;nbsp;&amp;nbsp;&amp;nbsp; before=lag(a);&lt;/P&gt;&lt;P&gt;518&amp;nbsp;&amp;nbsp;&amp;nbsp; set test;&lt;/P&gt;&lt;P&gt;519&amp;nbsp;&amp;nbsp;&amp;nbsp; after =lag(a);&lt;/P&gt;&lt;P&gt;520&amp;nbsp;&amp;nbsp;&amp;nbsp; put (a before after) (=);&lt;/P&gt;&lt;P&gt;521&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;a=1 before=. after=.&lt;/P&gt;&lt;P&gt;a=2 before=. after=1&lt;/P&gt;&lt;P&gt;a=3 before=1 after=2&lt;/P&gt;&lt;P&gt;a=4 before=2 after=3&lt;/P&gt;&lt;P&gt;a=5 before=3 after=4&lt;/P&gt;&lt;P&gt;a=6 before=4 after=5&lt;/P&gt;&lt;P&gt;a=7 before=5 after=6&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 20 Dec 2011 22:37:04 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2011-12-20T22:37:04Z</dc:date>
    <item>
      <title>data step execution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18216#M2707</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi everybody&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;there is two code which are acting differently. can anybody explain why?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hint: Lag function puls from queue!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;According to me they must procedure the same result!!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: 5px; vertical-align: baseline; background-color: #ffffff; position: static !important; color: #454545; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 16px; text-align: -webkit-auto;"&gt;&lt;SPAN style="vertical-align: baseline; position: static !important;"&gt;data test;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 5px; vertical-align: baseline; background-color: #ffffff; position: static !important; color: #454545; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 16px; text-align: -webkit-auto;"&gt;&lt;SPAN style="vertical-align: baseline; position: static !important;"&gt;INFILE datalines DLM=',' DSD;&lt;BR style="position: static !important;" /&gt;input a b c ;&lt;BR style="position: static !important;" /&gt;datalines;&lt;BR style="position: static !important;" /&gt;4272451,17878,17878&lt;BR style="position: static !important;" /&gt;4272451,17878,17878&lt;BR style="position: static !important;" /&gt;4272451,17887,17887&lt;BR style="position: static !important;" /&gt;4272454,17878,17878&lt;BR style="position: static !important;" /&gt;4272454,17881,17881&lt;BR style="position: static !important;" /&gt;4272454,17893,17893&lt;BR style="position: static !important;" /&gt;4272455,17878,17878&lt;BR style="position: static !important;" /&gt;4272455,17878,18200&lt;BR style="position: static !important;" /&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #454545; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 16px; text-align: -webkit-auto; background-color: #ffffff;"&gt;DATA TEST1; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #454545; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 16px; text-align: -webkit-auto; background-color: #ffffff;"&gt;RETAIN&amp;nbsp;&amp;nbsp; F ( 1) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #454545; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 16px; text-align: -webkit-auto; background-color: #ffffff;"&gt;&lt;SPAN style="color: #000000; font-family: Arial, Helvetica, 'Nimbus Sans L', sans-serif; line-height: 15px; text-align: -webkit-auto; background-color: #ffffff;"&gt;laga = lag(a); lagb=lag(b); &lt;/SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #454545; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 16px; text-align: -webkit-auto; background-color: #ffffff;"&gt;SET TEST;&lt;/SPAN&gt;&lt;STRONG style="color: #454545; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 16px; text-align: -webkit-auto; background-color: #ffffff; vertical-align: baseline; position: static !important;"&gt;&lt;EM style="vertical-align: baseline; position: static !important;"&gt;&lt;BR style="position: static !important;" /&gt;&lt;EM style="vertical-align: baseline; position: static !important;"&gt;IF A^=&lt;SPAN style="color: #000000; font-family: Arial, Helvetica, 'Nimbus Sans L', sans-serif; line-height: 15px; text-align: -webkit-auto; background-color: #ffffff;"&gt;laga &lt;/SPAN&gt; OR &lt;SPAN style="color: #000000; font-family: Arial, Helvetica, 'Nimbus Sans L', sans-serif; line-height: 15px; text-align: -webkit-auto; background-color: #ffffff;"&gt;laga &lt;/SPAN&gt;=.&amp;nbsp; THEN do;&amp;nbsp;&amp;nbsp;&amp;nbsp; f=1;end;&amp;nbsp; ELSE IF&amp;nbsp; A=&lt;SPAN style="color: #000000; font-family: Arial, Helvetica, 'Nimbus Sans L', sans-serif; line-height: 15px; text-align: -webkit-auto; background-color: #ffffff;"&gt;laga &lt;/SPAN&gt; &lt;SPAN style="vertical-align: baseline; position: static !important; text-decoration: underline;"&gt;&lt;EM style="vertical-align: baseline; position: static !important;"&gt;&lt;STRONG style="vertical-align: baseline; position: static !important;"&gt;AND b&amp;gt;&lt;SPAN style="color: #000000; font-family: Arial, Helvetica, 'Nimbus Sans L', sans-serif; line-height: 15px; text-align: -webkit-auto; background-color: #ffffff;"&gt;lagb&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/SPAN&gt; THEN do; f=f+1&amp;nbsp; ; end;&lt;/EM&gt;&lt;BR style="position: static !important;" /&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN style="color: #454545; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 16px; text-align: -webkit-auto; background-color: #ffffff;"&gt;RUN;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc print data=test1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: 5px; vertical-align: baseline; background-color: #ffffff; position: static !important; color: #454545; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 16px; text-align: -webkit-auto;"&gt;&lt;SPAN style="vertical-align: baseline; position: static !important;"&gt;DATA TEST2; &lt;BR style="position: static !important;" /&gt;RETAIN&amp;nbsp;&amp;nbsp; F (&amp;nbsp; 1) ;&lt;BR style="position: static !important;" /&gt;SET TEST;&lt;STRONG style="vertical-align: baseline; position: static !important;"&gt;&lt;EM style="vertical-align: baseline; position: static !important;"&gt;&lt;BR style="position: static !important;" /&gt;&lt;EM style="vertical-align: baseline; position: static !important;"&gt;IF A^=LAG(A) OR LAG(A)=.&amp;nbsp; THEN do;&amp;nbsp;&amp;nbsp;&amp;nbsp; f=1;end;&amp;nbsp; ELSE IF&amp;nbsp; A=LAG(A) &lt;SPAN style="vertical-align: baseline; position: static !important; text-decoration: underline;"&gt;&lt;EM style="vertical-align: baseline; position: static !important;"&gt;&lt;STRONG style="vertical-align: baseline; position: static !important;"&gt;AND b&amp;gt;LAG(B)&lt;/STRONG&gt;&lt;/EM&gt;&lt;/SPAN&gt; THEN do; f=f+1&amp;nbsp; ; end;&lt;/EM&gt;&lt;BR style="position: static !important;" /&gt;&lt;/EM&gt;&lt;/STRONG&gt;RUN;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc print data=test2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: 5px; vertical-align: baseline; background-color: #ffffff; position: static !important; color: #454545; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; line-height: 16px; text-align: -webkit-auto;"&gt;&lt;SPAN style="vertical-align: baseline; position: static !important;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Dec 2011 21:50:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18216#M2707</guid>
      <dc:creator>ender_akpil</dc:creator>
      <dc:date>2011-12-20T21:50:56Z</dc:date>
    </item>
    <item>
      <title>Re: data step execution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18217#M2708</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The problem is the ELSE clause.&amp;nbsp; This can cause the LAG(A) and LAG(B) functions in the second IF statement not to run on every iteration.&amp;nbsp; So instead of comparing the current value to the immediately preceding value you are comparing it to some value more than one observation earlier.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Dec 2011 22:03:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18217#M2708</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2011-12-20T22:03:48Z</dc:date>
    </item>
    <item>
      <title>data step execution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18218#M2709</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Tom, you are right..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Dec 2011 22:18:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18218#M2709</guid>
      <dc:creator>ender_akpil</dc:creator>
      <dc:date>2011-12-20T22:18:19Z</dc:date>
    </item>
    <item>
      <title>data step execution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18219#M2710</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Actually i have one more question. Why the lag function in the if and else part acting diffferently? they are on the same input line?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Dec 2011 22:24:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18219#M2710</guid>
      <dc:creator>ender_akpil</dc:creator>
      <dc:date>2011-12-20T22:24:07Z</dc:date>
    </item>
    <item>
      <title>data step execution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18220#M2711</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;An if statement functions from left to right and stops as soon as its condition is met&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Dec 2011 22:31:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18220#M2711</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-12-20T22:31:47Z</dc:date>
    </item>
    <item>
      <title>data step execution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18221#M2712</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;in the else part of the if satatement, lag fonctions will pull the value from previous, to determine the previous what value it will check? row number_ obs? _n_? which one?&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Dec 2011 22:33:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18221#M2712</guid>
      <dc:creator>ender_akpil</dc:creator>
      <dc:date>2011-12-20T22:33:55Z</dc:date>
    </item>
    <item>
      <title>Re: data step execution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18222#M2713</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You also have trouble with the location of your LAG function calls in the first case.&amp;nbsp; You have placed if BEFORE the SET statement.&lt;/P&gt;&lt;P&gt;This pushes an extra set of missing values onto the stack so that you end up getting the value from two observations before the call.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code"&gt;&lt;P&gt;516&amp;nbsp; data test2;&lt;/P&gt;&lt;P&gt;517&amp;nbsp;&amp;nbsp;&amp;nbsp; before=lag(a);&lt;/P&gt;&lt;P&gt;518&amp;nbsp;&amp;nbsp;&amp;nbsp; set test;&lt;/P&gt;&lt;P&gt;519&amp;nbsp;&amp;nbsp;&amp;nbsp; after =lag(a);&lt;/P&gt;&lt;P&gt;520&amp;nbsp;&amp;nbsp;&amp;nbsp; put (a before after) (=);&lt;/P&gt;&lt;P&gt;521&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;a=1 before=. after=.&lt;/P&gt;&lt;P&gt;a=2 before=. after=1&lt;/P&gt;&lt;P&gt;a=3 before=1 after=2&lt;/P&gt;&lt;P&gt;a=4 before=2 after=3&lt;/P&gt;&lt;P&gt;a=5 before=3 after=4&lt;/P&gt;&lt;P&gt;a=6 before=4 after=5&lt;/P&gt;&lt;P&gt;a=7 before=5 after=6&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Dec 2011 22:37:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18222#M2713</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2011-12-20T22:37:04Z</dc:date>
    </item>
    <item>
      <title>data step execution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18223#M2714</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It functions with a que, using the last value set.&amp;nbsp; However, the last value is only put into the cue when the statement is called. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Dec 2011 22:38:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18223#M2714</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-12-20T22:38:11Z</dc:date>
    </item>
    <item>
      <title>Re: data step execution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18224#M2715</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi ... you can have a LAG function within a conditional statement that does execute in every iteration of the data step if you use an IFN function instead of&amp;nbsp; your IF-THEN-ELSE statements...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;data test3;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;retain f 1;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;set test;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;f = ifn(a ne lag(a) or missing(lag(a)) , 1 , ifn(a eq lag(a) and b gt lag(b) , f+1 , f ));&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;run; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the above gives the same result as one of your data step, just modified slightly by moving the LAG statements after the SET statement ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;DATA TEST1;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;RETAIN&amp;nbsp;&amp;nbsp; F ( 1) ;&lt;/STRONG&gt; &lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;SET TEST;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;laga = lag(a); lagb=lag(b); &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;IF A^=laga OR laga =.&amp;nbsp; THEN do;&amp;nbsp;&amp;nbsp;&amp;nbsp; f=1;end;&amp;nbsp; ELSE IF&amp;nbsp; A=laga AND b&amp;gt;lagb THEN do; f=f+1&amp;nbsp; ; end;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;RUN;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;also fyi ... you don't need the DO-END stuff or the parentheses in the RETAIN and you can use a SUM statement ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;DATA TEST1;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;RETAIN F 1 ;&lt;/STRONG&gt; &lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;SET TEST;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;laga = lag(a); &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;lagb=lag(b); &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;IF A^=laga OR laga =. THEN f=1;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;ELSE &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;IF&amp;nbsp; A=laga AND b&amp;gt;lagb THEN f+1;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;RUN;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and ... since in the first pass through the data step, laga is missing, you can skip the RETAIN statement that gives F an intial value of 1 since F will be assigned a 1 in the first pass and the sum statement (F+1) is an "implied RETAIN" for F&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ps&amp;nbsp; you can read more about LAG and IF in Howard Schreier's paper ... "Conditional Lags Don't Have to be Treacherous"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; &lt;A class="active_link" href="http://www.howles.com/saspapers/CC33.pdf"&gt;http://www.howles.com/saspapers/CC33.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Dec 2011 22:40:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18224#M2715</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2011-12-20T22:40:52Z</dc:date>
    </item>
    <item>
      <title>data step execution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18225#M2716</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;this is very suprising for me!! why there is a extra missing step i couldnot understand.. but thanks i will think about it..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Dec 2011 22:46:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18225#M2716</guid>
      <dc:creator>ender_akpil</dc:creator>
      <dc:date>2011-12-20T22:46:05Z</dc:date>
    </item>
    <item>
      <title>data step execution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18226#M2717</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the answer Mike, it was helpful..&lt;/P&gt;&lt;P&gt;But i still searching lag function how determine the previous? if it gets from que why if and else part use different que?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Dec 2011 22:47:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18226#M2717</guid>
      <dc:creator>ender_akpil</dc:creator>
      <dc:date>2011-12-20T22:47:56Z</dc:date>
    </item>
    <item>
      <title>data step execution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18227#M2718</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try putting PUT statements before and after the SET statement to see when the values of the variables from the input dataset change.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Dec 2011 22:49:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18227#M2718</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2011-12-20T22:49:37Z</dc:date>
    </item>
    <item>
      <title>data step execution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18228#M2719</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thanks for the asnwer, but i still dont get it..&amp;nbsp; if and else part use same que ? or not? if they use same que then the lag function prodce same result for both part of if staatement.. if they dont use the same que then why? where the que for the else part? how can i reach it?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Dec 2011 22:49:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18228#M2719</guid>
      <dc:creator>ender_akpil</dc:creator>
      <dc:date>2011-12-20T22:49:59Z</dc:date>
    </item>
    <item>
      <title>data step execution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18229#M2720</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi ... it's not that a different part of the queue is used&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LAG gives you the value of a variable from the last time the LAG function was executed, NOT the value of the variable in the previous observation (that's what Tom told you)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;so ... if you use IF-THEN-ELSE without the statements ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LAGA = LAG(A);&lt;/P&gt;&lt;P&gt;LAGB = LAG(B);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;then LAG(A) and/or LAG(B) may not get executed during each pass through the data step&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Dec 2011 23:02:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18229#M2720</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2011-12-20T23:02:41Z</dc:date>
    </item>
    <item>
      <title>Re: data step execution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18230#M2721</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;And each place in the code where you have a LAG function will keep its own queue.&lt;/P&gt;&lt;P&gt;Look at this example.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code"&gt;&lt;P&gt;data x;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i=1 to 10 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; lag1=lag(i) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if i ne 4 then lag2=lag(i);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; put (i lag1 lag2) (=);&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i=1 lag1=. lag2=.&lt;/P&gt;&lt;P&gt;i=2 lag1=1 lag2=1&lt;/P&gt;&lt;P&gt;i=3 lag1=2 lag2=2&lt;/P&gt;&lt;P&gt;i=4 lag1=3 lag2=2&lt;/P&gt;&lt;P&gt;i=5 lag1=4 lag2=3&lt;/P&gt;&lt;P&gt;i=6 lag1=5 lag2=5&lt;/P&gt;&lt;P&gt;i=7 lag1=6 lag2=6&lt;/P&gt;&lt;P&gt;i=8 lag1=7 lag2=7&lt;/P&gt;&lt;P&gt;i=9 lag1=8 lag2=8&lt;/P&gt;&lt;P&gt;i=10 lag1=9 lag2=9&lt;/P&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Dec 2011 23:08:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18230#M2721</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2011-12-20T23:08:34Z</dc:date>
    </item>
    <item>
      <title>data step execution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18231#M2722</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;OK .. i understand the last time execution.. but then i have to ask&amp;nbsp; last time execution of if part is different from last time execution of else part? since according to to Tom else part is not executed in every iteration? but then there must be a log or something else that with help of it&amp;nbsp; lag knows from where it will continue? isnt it?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lets create a scnenario: there is data and if then-else statement and lag function in each part:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Observation 1: if part true&amp;nbsp; and lag in the if part is executed. lag in the else part is not executed &lt;/P&gt;&lt;P&gt;Observation 2: if part true&amp;nbsp; and lag in the if part is executed. lag in the else part is not executed&lt;/P&gt;&lt;P&gt;Observation 3: if part false and lag in the if part is &lt;SPAN style="text-decoration: underline;"&gt;not&lt;/SPAN&gt; executed. lag in the else part &lt;SPAN style="text-decoration: underline;"&gt;is executed&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;what is the value of lag in the third observation?&lt;SPAN style="text-decoration: underline;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Dec 2011 23:14:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18231#M2722</guid>
      <dc:creator>ender_akpil</dc:creator>
      <dc:date>2011-12-20T23:14:56Z</dc:date>
    </item>
    <item>
      <title>data step execution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18232#M2723</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Since it is the first time that it executed the result of any LAG() function calls in the ELSE part on the third iteration will be missing values.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Dec 2011 23:20:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18232#M2723</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2011-12-20T23:20:18Z</dc:date>
    </item>
    <item>
      <title>data step execution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18233#M2724</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Tom, this is very nice code..&lt;/P&gt;&lt;P&gt;I have a question about lag2 variable, if lag's in the data step follw their own que then lag2 values should be:&lt;/P&gt;&lt;P&gt;lag2=.&lt;/P&gt;&lt;P&gt;lag2=1&lt;/P&gt;&lt;P&gt;lag2=2 &lt;/P&gt;&lt;P&gt;lag2=2&lt;/P&gt;&lt;P&gt;lag2=3&lt;/P&gt;&lt;P&gt;lag2=4&lt;/P&gt;&lt;P&gt;lag2=5&lt;/P&gt;&lt;P&gt;lag2=6&lt;/P&gt;&lt;P&gt;lag2=7&lt;/P&gt;&lt;P&gt;lag2=8&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;lag2=9&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;but according to ypur result in line 6 in turns to normal flow?&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Dec 2011 23:23:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18233#M2724</guid>
      <dc:creator>ender_akpil</dc:creator>
      <dc:date>2011-12-20T23:23:36Z</dc:date>
    </item>
    <item>
      <title>data step execution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18234#M2725</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When LAG() is called the top of the stack is returned and the current value is pushed onto the stack.&lt;/P&gt;&lt;P&gt;When I=1 then missing is returned and 1 is pushed.&lt;/P&gt;&lt;P&gt;When I=2 then 1 is returned and 2 is pushed.&lt;/P&gt;&lt;P&gt;When I=3 then 2 is returned and 3 is pushed.&lt;/P&gt;&lt;P&gt;When I=4 it is skipped so LAG2 stays as 2.&lt;/P&gt;&lt;P&gt;When I=5 then 3 is returned and 5 is pushed.&lt;/P&gt;&lt;P&gt;When I=6 then 5 is returned and 6 is pushed.&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Dec 2011 00:03:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18234#M2725</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2011-12-21T00:03:32Z</dc:date>
    </item>
    <item>
      <title>data step execution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18235#M2726</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Thanks Tom..&lt;/P&gt;&lt;P&gt;Still i want to ask, should lag function should use same que? i mean this is more meaningfull isnt it?&lt;/P&gt;&lt;P&gt;I come across with this problem while i was searching equivalent of oracle partitioned analytic query ( row_number over (partition by a order by b asc) )&lt;/P&gt;&lt;P&gt;Is there a anoher way to do this?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Dec 2011 07:58:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-execution/m-p/18235#M2726</guid>
      <dc:creator>ender_akpil</dc:creator>
      <dc:date>2011-12-21T07:58:04Z</dc:date>
    </item>
  </channel>
</rss>

