<?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: first.gvkey in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/first-gvkey/m-p/687945#M208910</link>
    <description>Lag cannot be calculated conditionally, so calculate it all the time and then set it to missing AFTER.&lt;BR /&gt;&lt;BR /&gt;want = lag(at);&lt;BR /&gt;if first.gvkey then call missing(want);</description>
    <pubDate>Wed, 30 Sep 2020 19:07:54 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-09-30T19:07:54Z</dc:date>
    <item>
      <title>first.gvkey</title>
      <link>https://communities.sas.com/t5/SAS-Programming/first-gvkey/m-p/687942#M208907</link>
      <description>&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;gvkey&lt;/TD&gt;&lt;TD&gt;fyear&lt;/TD&gt;&lt;TD&gt;at&lt;/TD&gt;&lt;TD&gt;want&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1001&lt;/TD&gt;&lt;TD&gt;2001&lt;/TD&gt;&lt;TD&gt;12.3&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1001&lt;/TD&gt;&lt;TD&gt;2002&lt;/TD&gt;&lt;TD&gt;13.6&lt;/TD&gt;&lt;TD&gt;12.3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1001&lt;/TD&gt;&lt;TD&gt;2003&lt;/TD&gt;&lt;TD&gt;12.6&lt;/TD&gt;&lt;TD&gt;13.6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1001&lt;/TD&gt;&lt;TD&gt;2004&lt;/TD&gt;&lt;TD&gt;11.9&lt;/TD&gt;&lt;TD&gt;12.6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1002&lt;/TD&gt;&lt;TD&gt;2001&lt;/TD&gt;&lt;TD&gt;13.4&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1002&lt;/TD&gt;&lt;TD&gt;2002&lt;/TD&gt;&lt;TD&gt;17.7&lt;/TD&gt;&lt;TD&gt;13.4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1002&lt;/TD&gt;&lt;TD&gt;2003&lt;/TD&gt;&lt;TD&gt;18.4&lt;/TD&gt;&lt;TD&gt;17.7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1002&lt;/TD&gt;&lt;TD&gt;2004&lt;/TD&gt;&lt;TD&gt;15.1&lt;/TD&gt;&lt;TD&gt;18.4&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;by gvkey fyear;&lt;/P&gt;&lt;P&gt;if first.gvkey then want=.;&lt;/P&gt;&lt;P&gt;else want=lag(at);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My data is already sorted. I am not getting the expected result. What is the mistake here?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 19:02:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/first-gvkey/m-p/687942#M208907</guid>
      <dc:creator>abdulla</dc:creator>
      <dc:date>2020-09-30T19:02:08Z</dc:date>
    </item>
    <item>
      <title>Re: first.gvkey</title>
      <link>https://communities.sas.com/t5/SAS-Programming/first-gvkey/m-p/687944#M208909</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/260675"&gt;@abdulla&lt;/a&gt;&amp;nbsp; &amp;nbsp;Can you include both your input data and your expected result?&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 19:05:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/first-gvkey/m-p/687944#M208909</guid>
      <dc:creator>mklangley</dc:creator>
      <dc:date>2020-09-30T19:05:15Z</dc:date>
    </item>
    <item>
      <title>Re: first.gvkey</title>
      <link>https://communities.sas.com/t5/SAS-Programming/first-gvkey/m-p/687945#M208910</link>
      <description>Lag cannot be calculated conditionally, so calculate it all the time and then set it to missing AFTER.&lt;BR /&gt;&lt;BR /&gt;want = lag(at);&lt;BR /&gt;if first.gvkey then call missing(want);</description>
      <pubDate>Wed, 30 Sep 2020 19:07:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/first-gvkey/m-p/687945#M208910</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-09-30T19:07:54Z</dc:date>
    </item>
    <item>
      <title>Re: first.gvkey</title>
      <link>https://communities.sas.com/t5/SAS-Programming/first-gvkey/m-p/687946#M208911</link>
      <description>&lt;P&gt;Never use LAG conditionally (unless you&amp;nbsp;&lt;EM&gt;really&lt;/EM&gt; know what you are doing). Slightly change your code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by gvkey fyear;
want = lag(at);
if first.gvkey then want = .;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is necessary because LAG will only put a value into the queue when it is called.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 19:08:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/first-gvkey/m-p/687946#M208911</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-30T19:08:05Z</dc:date>
    </item>
    <item>
      <title>Re: first.gvkey</title>
      <link>https://communities.sas.com/t5/SAS-Programming/first-gvkey/m-p/687947#M208912</link>
      <description>The first three columns are my data and the fourth column is my expected result.</description>
      <pubDate>Wed, 30 Sep 2020 19:08:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/first-gvkey/m-p/687947#M208912</guid>
      <dc:creator>abdulla</dc:creator>
      <dc:date>2020-09-30T19:08:25Z</dc:date>
    </item>
    <item>
      <title>Re: first.gvkey</title>
      <link>https://communities.sas.com/t5/SAS-Programming/first-gvkey/m-p/687951#M208916</link>
      <description>Thank you</description>
      <pubDate>Wed, 30 Sep 2020 19:13:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/first-gvkey/m-p/687951#M208916</guid>
      <dc:creator>abdulla</dc:creator>
      <dc:date>2020-09-30T19:13:23Z</dc:date>
    </item>
  </channel>
</rss>

