<?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 with LAG or RETAIN? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47326#M12704</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can anyone suggest a good tutorial for more advanced data step functions?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This sort of thing (&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://www2.sas.com/proceedings/sugi30/134-30.pdf"&gt;http://www2.sas.com/proceedings/sugi30/134-30.pdf&lt;/A&gt;&lt;SPAN&gt;) I know inside and out.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 07 Feb 2012 16:09:32 GMT</pubDate>
    <dc:creator>iiibbb</dc:creator>
    <dc:date>2012-02-07T16:09:32Z</dc:date>
    <item>
      <title>Help with LAG or RETAIN?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47310#M12688</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P class="postbody"&gt;I have a time dataset.&amp;nbsp; I have 4 columns in this dataset that identify the zone a machine occupies as it moves from one place to another.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to create a field that increases by 1 whenever the data being collected changes from one state to another -- essentially I want to assign leg numbers, with a new leg beginning anytime it changes from one zone to another.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I thought I could do this using the LAG function with some if/then statements, but I'm apparently doing something wrong.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now I wonder if the RETAIN might be what I need to use.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help would be appreciated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Feb 2012 19:30:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47310#M12688</guid>
      <dc:creator>iiibbb</dc:creator>
      <dc:date>2012-02-06T19:30:25Z</dc:date>
    </item>
    <item>
      <title>Re: Help with LAG or RETAIN?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47311#M12689</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi ... so is this supposed to start at 1, then 2, etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;data x;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;input zone @@;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;datalines;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;66 66 66 77 77 77 77 888 888 9999 9999&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;;&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;&lt;STRONG style="font-family: 'courier new', courier;"&gt;data x;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;set x;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;by zone;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;leg + first.zone&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;&lt;STRONG style="font-family: 'courier new', courier;"&gt;zone&amp;nbsp;&amp;nbsp;&amp;nbsp; leg&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG style="font-family: 'courier new', courier;"&gt;66&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;&amp;nbsp; 66&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;&amp;nbsp; 66&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;&amp;nbsp; 77&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;&amp;nbsp; 77&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;&amp;nbsp; 77&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;&amp;nbsp; 77&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt; 888&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt; 888&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;9999&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;9999&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Feb 2012 19:38:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47311#M12689</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2012-02-06T19:38:00Z</dc:date>
    </item>
    <item>
      <title>Re: Help with LAG or RETAIN?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47312#M12690</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That almost works except sometimes the machine re-enters a zone, but on a new leg.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And yes, the start leg is leg 1.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Feb 2012 19:44:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47312#M12690</guid>
      <dc:creator>iiibbb</dc:creator>
      <dc:date>2012-02-06T19:44:53Z</dc:date>
    </item>
    <item>
      <title>Re: Help with LAG or RETAIN?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47313#M12691</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;the practice dataset looks like this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" width="413"&gt;&lt;TBODY&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD height="20" style="height: 15pt; width: 67pt;" width="89"&gt;UTC_Seconds&lt;/TD&gt;&lt;TD style="width: 41pt;" width="55"&gt;Landing&lt;/TD&gt;&lt;TD style="width: 22pt;" width="29"&gt;HL1&lt;/TD&gt;&lt;TD style="width: 29pt;" width="38"&gt;Field&lt;/TD&gt;&lt;TD style="width: 22pt;" width="29"&gt;HL2&lt;/TD&gt;&lt;TD style="width: 35pt;" width="46"&gt;Speed&lt;/TD&gt;&lt;TD style="width: 47pt;" width="63"&gt;Dummy&lt;/TD&gt;&lt;TD style="width: 48pt;" width="64"&gt;&lt;BR /&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD align="right" height="20" style="height: 15pt;"&gt;10001&lt;/TD&gt;&lt;TD align="right"&gt;1&lt;/TD&gt;&lt;TD align="right"&gt;0&lt;/TD&gt;&lt;TD align="right"&gt;0&lt;/TD&gt;&lt;TD align="right"&gt;0&lt;/TD&gt;&lt;TD align="right"&gt;1&lt;/TD&gt;&lt;TD align="right"&gt;10000001&lt;/TD&gt;&lt;TD&gt;&lt;BR /&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD align="right" height="20" style="height: 15pt;"&gt;10002&lt;/TD&gt;&lt;TD align="right"&gt;1&lt;/TD&gt;&lt;TD align="right"&gt;0&lt;/TD&gt;&lt;TD align="right"&gt;0&lt;/TD&gt;&lt;TD align="right"&gt;0&lt;/TD&gt;&lt;TD align="right"&gt;1&lt;/TD&gt;&lt;TD align="right"&gt;10000002&lt;/TD&gt;&lt;TD&gt;&lt;BR /&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD align="right" height="20" style="height: 15pt;"&gt;10003&lt;/TD&gt;&lt;TD align="right"&gt;1&lt;/TD&gt;&lt;TD align="right"&gt;0&lt;/TD&gt;&lt;TD align="right"&gt;0&lt;/TD&gt;&lt;TD align="right"&gt;0&lt;/TD&gt;&lt;TD align="right"&gt;1&lt;/TD&gt;&lt;TD align="right"&gt;10000003&lt;/TD&gt;&lt;TD&gt;&lt;BR /&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD align="right" height="20" style="height: 15pt;"&gt;10004&lt;/TD&gt;&lt;TD align="right"&gt;1&lt;/TD&gt;&lt;TD align="right"&gt;0&lt;/TD&gt;&lt;TD align="right"&gt;0&lt;/TD&gt;&lt;TD align="right"&gt;0&lt;/TD&gt;&lt;TD align="right"&gt;1&lt;/TD&gt;&lt;TD align="right"&gt;10000004&lt;/TD&gt;&lt;TD&gt;&lt;BR /&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD align="right" height="20" style="height: 15pt;"&gt;10005&lt;/TD&gt;&lt;TD align="right"&gt;1&lt;/TD&gt;&lt;TD align="right"&gt;0&lt;/TD&gt;&lt;TD align="right"&gt;0&lt;/TD&gt;&lt;TD align="right"&gt;0&lt;/TD&gt;&lt;TD align="right"&gt;1&lt;/TD&gt;&lt;TD align="right"&gt;10000005&lt;/TD&gt;&lt;TD&gt;&lt;BR /&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD align="right" height="20" style="height: 15pt;"&gt;10006&lt;/TD&gt;&lt;TD align="right"&gt;1&lt;/TD&gt;&lt;TD align="right"&gt;0&lt;/TD&gt;&lt;TD align="right"&gt;0&lt;/TD&gt;&lt;TD align="right"&gt;0&lt;/TD&gt;&lt;TD align="right"&gt;1&lt;/TD&gt;&lt;TD align="right"&gt;10000006&lt;/TD&gt;&lt;TD&gt;&lt;BR /&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD align="right" height="20" style="height: 15pt;"&gt;10007&lt;/TD&gt;&lt;TD align="right"&gt;1&lt;/TD&gt;&lt;TD align="right"&gt;0&lt;/TD&gt;&lt;TD align="right"&gt;0&lt;/TD&gt;&lt;TD align="right"&gt;0&lt;/TD&gt;&lt;TD align="right"&gt;1&lt;/TD&gt;&lt;TD align="right"&gt;10000007&lt;/TD&gt;&lt;TD&gt;&lt;BR /&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD align="right" height="20" style="height: 15pt;"&gt;10008&lt;/TD&gt;&lt;TD align="right"&gt;1&lt;/TD&gt;&lt;TD align="right"&gt;0&lt;/TD&gt;&lt;TD align="right"&gt;0&lt;/TD&gt;&lt;TD align="right"&gt;0&lt;/TD&gt;&lt;TD align="right"&gt;2&lt;/TD&gt;&lt;TD align="right"&gt;10000008&lt;/TD&gt;&lt;TD&gt;&lt;BR /&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD align="right" height="20" style="height: 15pt;"&gt;10009&lt;/TD&gt;&lt;TD align="right"&gt;1&lt;/TD&gt;&lt;TD align="right"&gt;0&lt;/TD&gt;&lt;TD align="right"&gt;0&lt;/TD&gt;&lt;TD align="right"&gt;0&lt;/TD&gt;&lt;TD align="right"&gt;2&lt;/TD&gt;&lt;TD align="right"&gt;10000009&lt;/TD&gt;&lt;TD&gt;&lt;BR /&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But in part of the code I do assign a single variable to describe location&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data a;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set timestd.practice;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*segmentation and control points*/&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data b;&lt;/P&gt;&lt;P&gt;set a;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if landing = 1 then Leg_Type = 'LANDING';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if HL1 = 1 then Leg_Type = 'HL1';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if Field = 1 then Leg_Type = 'FIELD';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if HL2 = 1 then Leg_Type = 'HL2';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if HL2 + Field + HL2 + Landing = 0 then Leg_Type = 'TRANS';&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data c;&lt;/P&gt;&lt;P&gt;set b;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* these statements want me to sort the data by leg_type */ &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by leg_type;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; leg + first.legtype;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc print;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Feb 2012 19:48:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47313#M12691</guid>
      <dc:creator>iiibbb</dc:creator>
      <dc:date>2012-02-06T19:48:58Z</dc:date>
    </item>
    <item>
      <title>Re: Help with LAG or RETAIN?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47314#M12692</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm still tinkering with it, but It appears that if I use the line&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if Leg_Type = Lag1(Leg_Type) then CP=0; else CP=1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I can create a dataset that looks the same as if I had used a first. variable in the datastep processing... based on this website's information,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="jive-link-external-small" href="http://www.pauldickman.com/teaching/sas/set_by.php"&gt;http://www.pauldickman.com/teaching/sas/set_by.php&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; but I don't have the groups.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How can I reverse this to create the groups?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Feb 2012 20:34:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47314#M12692</guid>
      <dc:creator>iiibbb</dc:creator>
      <dc:date>2012-02-06T20:34:12Z</dc:date>
    </item>
    <item>
      <title>Re: Help with LAG or RETAIN?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47315#M12693</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You don't have to reverse it so much as change what you want to do when the condition is met.&amp;nbsp; I think you are asking how one does something like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #eef4f9;"&gt; if Leg_Type ne Lag1(Leg_Type) then group+1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #eef4f9;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Feb 2012 20:43:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47315#M12693</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-02-06T20:43:16Z</dc:date>
    </item>
    <item>
      <title>Re: Help with LAG or RETAIN?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47316#M12694</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That's what I thought would work.&amp;nbsp; But that yields the same result as &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if Leg_Type = Lag1(Leg_Type) then CP=0; else CP=1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Which is still useful to me because it identifies my control points (the first point of every leg).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, with &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #eef4f9;"&gt;if Leg_Type ne Lag1(Leg_Type) then leg+1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I get 0's except when I change type, I get a single 1, and then it goes back to zeros.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Feb 2012 20:49:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47316#M12694</guid>
      <dc:creator>iiibbb</dc:creator>
      <dc:date>2012-02-06T20:49:38Z</dc:date>
    </item>
    <item>
      <title>Re: Help with LAG or RETAIN?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47317#M12695</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I may not understand what you are trying to do but, using a slight extension of Mike's test data, does the following do what you want?:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data x;&lt;/P&gt;&lt;P&gt;input leg_type @@;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;66 66 66 77 77 77 77 66 66 888 888 77 77 77 9999 9999&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set x;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by leg_type notsorted;&lt;/P&gt;&lt;P&gt;&amp;nbsp; leg + first.leg_type;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Feb 2012 21:06:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47317#M12695</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-02-06T21:06:27Z</dc:date>
    </item>
    <item>
      <title>Re: Help with LAG or RETAIN?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47318#M12696</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you both!!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Feb 2012 21:17:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47318#M12696</guid>
      <dc:creator>iiibbb</dc:creator>
      <dc:date>2012-02-06T21:17:29Z</dc:date>
    </item>
    <item>
      <title>Re: Help with LAG or RETAIN?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47319#M12697</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;FYI&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I just learned statements can not be used (reliably) in conditional statements.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="jive-link-external-small" href="http://www.nesug.org/proceedings/nesug06/cc/cc32.pdf"&gt;http://www.nesug.org/proceedings/nesug06/cc/cc32.pdf&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Feb 2012 02:48:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47319#M12697</guid>
      <dc:creator>iiibbb</dc:creator>
      <dc:date>2012-02-07T02:48:13Z</dc:date>
    </item>
    <item>
      <title>Re: Help with LAG or RETAIN?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47320#M12698</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Always a good lesson to learn but, in the code you had posted, you didn't have any conditional use of a lag statement.&amp;nbsp; If you did in the actual code you ran then, yes, you could easily run into trouble.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, its not because the statement can't be used reliably but, more so, that they will be doing things other than what you had intended.&amp;nbsp; But quite reliably!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Feb 2012 03:42:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47320#M12698</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-02-07T03:42:05Z</dc:date>
    </item>
    <item>
      <title>Re: Help with LAG or RETAIN?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47321#M12699</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I kind-of disagree.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;--------------------------------&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #eef4f9;"&gt;if AAA ne Lag1(AAA) then BBB=BBB+1; else BBB=BBB;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;--------------------------------&lt;/P&gt;&lt;P&gt;LagAAA = Lag1(AAA);&lt;/P&gt;&lt;P&gt;if AAA ne LagAAA then BBB=BBB+1; else BBB=BBB;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Logically, these should be the same.&amp;nbsp; But based on this experience, they do not yield the same result in certain conditional statements.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But thank you for solving my problem.&amp;nbsp; And now I know how to do it with the lag statement too.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Feb 2012 14:32:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47321#M12699</guid>
      <dc:creator>iiibbb</dc:creator>
      <dc:date>2012-02-07T14:32:42Z</dc:date>
    </item>
    <item>
      <title>Re: Help with LAG or RETAIN?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47322#M12700</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Would you post some data and code that shows a situation where you get different results using the two methods?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The following example appears to produce the exact same result:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input aaa bbb;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;1 1&lt;/P&gt;&lt;P&gt;1 2&lt;/P&gt;&lt;P&gt;2 3&lt;/P&gt;&lt;P&gt;2 4&lt;/P&gt;&lt;P&gt;1 5&lt;/P&gt;&lt;P&gt;3 6&lt;/P&gt;&lt;P&gt;3 7&lt;/P&gt;&lt;P&gt;3 8&lt;/P&gt;&lt;P&gt;4 9&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if AAA ne Lag1(AAA) then BBB=BBB+1; &lt;/P&gt;&lt;P&gt;&amp;nbsp; else BBB=BBB;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; LagAAA = Lag1(AAA);&lt;/P&gt;&lt;P&gt;&amp;nbsp; if AAA ne LagAAA then BBB=BBB+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else BBB=BBB;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Feb 2012 14:41:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47322#M12700</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-02-07T14:41:15Z</dc:date>
    </item>
    <item>
      <title>Re: Help with LAG or RETAIN?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47323#M12701</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Art,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Notice the words that iiibbb used "result in certain conditional statements."&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I suspect you are not being told the whole story.&amp;nbsp; Most of us know what happens when LAG is executed conditionally.&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Feb 2012 14:52:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47323#M12701</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2012-02-07T14:52:40Z</dc:date>
    </item>
    <item>
      <title>Re: Help with LAG or RETAIN?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47324#M12702</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;DN, That is why I posted an earlier response to iiibbb, namely: &lt;SPAN style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"&gt;Always a good lesson to learn but, in the code you had posted, you didn't have any conditional use of a lag statement.&amp;nbsp; If you did in the actual code you ran then, yes, you could easily run into trouble.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"&gt;Yes, I agree that using lag conditionally requires that one knows how the cue works, but I'm afraid that iiibbb will throw the baby out with the bath water for not understanding what is meant by conditional use.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Feb 2012 15:01:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47324#M12702</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-02-07T15:01:35Z</dc:date>
    </item>
    <item>
      <title>Re: Help with LAG or RETAIN?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47325#M12703</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'll admit I'm a neophite.&amp;nbsp; I wish I had the code that botched my sorting.&amp;nbsp; I've already replaced it with code that works (I generally like to destroy non-working code as quick as possible)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, I'm certain I had a well laid out logic that didn't work when it was built into the if/then statement... and worked as soon as I created a stand-alone variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Needless to say, a learning experience, and I hope that I will come to better understand how this works in the future.&amp;nbsp; I've not worked with data like this before and I'm learning all sorts of new and fun things.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;At least I can tell when something is not working &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Feb 2012 16:07:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47325#M12703</guid>
      <dc:creator>iiibbb</dc:creator>
      <dc:date>2012-02-07T16:07:11Z</dc:date>
    </item>
    <item>
      <title>Re: Help with LAG or RETAIN?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47326#M12704</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can anyone suggest a good tutorial for more advanced data step functions?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This sort of thing (&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://www2.sas.com/proceedings/sugi30/134-30.pdf"&gt;http://www2.sas.com/proceedings/sugi30/134-30.pdf&lt;/A&gt;&lt;SPAN&gt;) I know inside and out.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Feb 2012 16:09:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47326#M12704</guid>
      <dc:creator>iiibbb</dc:creator>
      <dc:date>2012-02-07T16:09:32Z</dc:date>
    </item>
    <item>
      <title>Re: Help with LAG or RETAIN?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47327#M12705</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A fairly simple article that describes the problem with using the lag function, conditionally, is shown at: &lt;A href="http://www.nesug.org/proceedings/nesug06/cc/cc32.pdf"&gt;http://www.nesug.org/proceedings/nesug06/cc/cc32.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There is a site that has all of the global forum papers as well as many of the regional papers: &lt;A href="http://www.lexjansen.com/"&gt;http://www.lexjansen.com/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There is always the documentation: &lt;A href="http://support.sas.com/documentation/93/index.html"&gt;http://support.sas.com/documentation/93/index.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and sasCommunity.org articles: &lt;A href="http://www.sascommunity.org/wiki/Main_Page"&gt;http://www.sascommunity.org/wiki/Main_Page&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and many, many books by SAS users: &lt;A href="http://support.sas.com/community/authors/index.html"&gt;http://support.sas.com/community/authors/index.html&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Feb 2012 16:20:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47327#M12705</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-02-07T16:20:25Z</dc:date>
    </item>
    <item>
      <title>Re: Help with LAG or RETAIN?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47328#M12706</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Two authors you can look for:&amp;nbsp; Ron Cody and Ben Cochran.&amp;nbsp; You may have to search through the titles, though, to find the papers you're looking for.&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>Tue, 07 Feb 2012 16:32:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47328#M12706</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2012-02-07T16:32:23Z</dc:date>
    </item>
    <item>
      <title>Re: Help with LAG or RETAIN?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47329#M12707</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Astounding:&amp;nbsp; Absolutely nothing wrong with reading those authors, but I definitely wouldn't limit who I'd suggest reading.&amp;nbsp; There are many, many outstanding authors and not all of them have elected to write books.&amp;nbsp; I'd list some of my own favorites, but that would take a book in itself.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Feb 2012 16:59:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-LAG-or-RETAIN/m-p/47329#M12707</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-02-07T16:59:09Z</dc:date>
    </item>
  </channel>
</rss>

