<?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: Getting the real LAG of a certain variable! in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Getting-the-real-LAG-of-a-certain-variable/m-p/41593#M10757</link>
    <description>Thanks Cynthia!&lt;BR /&gt;
&lt;BR /&gt;
Since I have quarterly data, that means I have nearly 44 rows for each company in my sample. For each quarter I need to get the (lag4), which means that I need to set the first 4 rows of each company as (.). I did it now by "if first.company then lag4=."&lt;BR /&gt;
&lt;BR /&gt;
Appreciate your help though &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
    <pubDate>Thu, 21 Jan 2010 10:55:20 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2010-01-21T10:55:20Z</dc:date>
    <item>
      <title>Getting the real LAG of a certain variable!</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Getting-the-real-LAG-of-a-certain-variable/m-p/41591#M10755</link>
      <description>How can I resolve the pifall of the lag function?&lt;BR /&gt;
I mean I want the real lag not not the one created by lag_var =  lag (var) !</description>
      <pubDate>Fri, 15 Jan 2010 19:55:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Getting-the-real-LAG-of-a-certain-variable/m-p/41591#M10755</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-01-15T19:55:20Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the real LAG of a certain variable!</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Getting-the-real-LAG-of-a-certain-variable/m-p/41592#M10756</link>
      <description>Hi:&lt;BR /&gt;
  Given this data (SASHELP.CLASS):&lt;BR /&gt;
[pre]&lt;BR /&gt;
Before Lag&lt;BR /&gt;
&lt;BR /&gt;
Obs    Name       Sex    Age    Height    Weight&lt;BR /&gt;
&lt;BR /&gt;
  1    Alice       F      13     56.5       84.0&lt;BR /&gt;
  2    Barbara     F      13     65.3       98.0&lt;BR /&gt;
  3    Carol       F      14     62.8      102.5&lt;BR /&gt;
  4    Jane        F      12     59.8       84.5&lt;BR /&gt;
  5    Janet       F      15     62.5      112.5&lt;BR /&gt;
  6    Joyce       F      11     51.3       50.5&lt;BR /&gt;
  7    Judy        F      14     64.3       90.0&lt;BR /&gt;
  8    Louise      F      12     56.3       77.0&lt;BR /&gt;
  9    Mary        F      15     66.5      112.0&lt;BR /&gt;
 10    Alfred      M      14     69.0      112.5&lt;BR /&gt;
 11    Henry       M      14     63.5      102.5&lt;BR /&gt;
 12    James       M      12     57.3       83.0&lt;BR /&gt;
 13    Jeffrey     M      13     62.5       84.0&lt;BR /&gt;
 14    John        M      12     59.0       99.5&lt;BR /&gt;
 15    Philip      M      16     72.0      150.0&lt;BR /&gt;
 16    Robert      M      12     64.8      128.0&lt;BR /&gt;
 17    Ronald      M      15     67.0      133.0&lt;BR /&gt;
 18    Thomas      M      11     57.5       85.0&lt;BR /&gt;
 19    William     M      15     66.5      112.0&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                                      &lt;BR /&gt;
...and this program:&lt;BR /&gt;
[pre]&lt;BR /&gt;
options ls=80 nocenter nodate nonumber;&lt;BR /&gt;
proc print data=sashelp.class;&lt;BR /&gt;
  title 'Before Lag';&lt;BR /&gt;
run;&lt;BR /&gt;
                    &lt;BR /&gt;
data lagclass;&lt;BR /&gt;
  set sashelp.class;&lt;BR /&gt;
  by sex;&lt;BR /&gt;
  lagage = lag(age);&lt;BR /&gt;
  if first.sex then lagage = .;&lt;BR /&gt;
run;&lt;BR /&gt;
             &lt;BR /&gt;
ods listing;&lt;BR /&gt;
proc print data=lagclass;&lt;BR /&gt;
  title 'After Lag';&lt;BR /&gt;
  var name sex age lagage height weight;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                              &lt;BR /&gt;
I don't understand what you mean by the "pitfall of the lag function". The above program produces this output:&lt;BR /&gt;
[pre]&lt;BR /&gt;
After Lag&lt;BR /&gt;
                      &lt;BR /&gt;
Obs    Name       Sex    Age    lagage    Height    Weight&lt;BR /&gt;
   &lt;BR /&gt;
  1    Alice       F      13       .       56.5       84.0&lt;BR /&gt;
  2    Barbara     F      13      13       65.3       98.0&lt;BR /&gt;
  3    Carol       F      14      13       62.8      102.5&lt;BR /&gt;
  4    Jane        F      12      14       59.8       84.5&lt;BR /&gt;
  5    Janet       F      15      12       62.5      112.5&lt;BR /&gt;
  6    Joyce       F      11      15       51.3       50.5&lt;BR /&gt;
  7    Judy        F      14      11       64.3       90.0&lt;BR /&gt;
  8    Louise      F      12      14       56.3       77.0&lt;BR /&gt;
  9    Mary        F      15      12       66.5      112.0&lt;BR /&gt;
 10    Alfred      M      14       .       69.0      112.5&lt;BR /&gt;
 11    Henry       M      14      14       63.5      102.5&lt;BR /&gt;
 12    James       M      12      14       57.3       83.0&lt;BR /&gt;
 13    Jeffrey     M      13      12       62.5       84.0&lt;BR /&gt;
 14    John        M      12      13       59.0       99.5&lt;BR /&gt;
 15    Philip      M      16      12       72.0      150.0&lt;BR /&gt;
 16    Robert      M      12      16       64.8      128.0&lt;BR /&gt;
 17    Ronald      M      15      12       67.0      133.0&lt;BR /&gt;
 18    Thomas      M      11      15       57.5       85.0&lt;BR /&gt;
 19    William     M      15      11       66.5      112.0&lt;BR /&gt;
               &lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                               &lt;BR /&gt;
These Tech Support notes and user-group paper have more information:&lt;BR /&gt;
&lt;A href="http://support.sas.com/kb/24/694.html" target="_blank"&gt;http://support.sas.com/kb/24/694.html&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://support.sas.com/kb/24/665.html" target="_blank"&gt;http://support.sas.com/kb/24/665.html&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://support.sas.com/resources/papers/proceedings09/055-2009.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings09/055-2009.pdf&lt;/A&gt;&lt;BR /&gt;
 &lt;BR /&gt;
Perhaps your questions about the LAG function will be answered by these documents.&lt;BR /&gt;
   &lt;BR /&gt;
cynthia</description>
      <pubDate>Fri, 15 Jan 2010 20:46:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Getting-the-real-LAG-of-a-certain-variable/m-p/41592#M10756</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-01-15T20:46:33Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the real LAG of a certain variable!</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Getting-the-real-LAG-of-a-certain-variable/m-p/41593#M10757</link>
      <description>Thanks Cynthia!&lt;BR /&gt;
&lt;BR /&gt;
Since I have quarterly data, that means I have nearly 44 rows for each company in my sample. For each quarter I need to get the (lag4), which means that I need to set the first 4 rows of each company as (.). I did it now by "if first.company then lag4=."&lt;BR /&gt;
&lt;BR /&gt;
Appreciate your help though &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Thu, 21 Jan 2010 10:55:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Getting-the-real-LAG-of-a-certain-variable/m-p/41593#M10757</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-01-21T10:55:20Z</dc:date>
    </item>
  </channel>
</rss>

