<?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: Why summary statistic of lag value is identical to that of original variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Why-summary-statistic-of-lag-value-is-identical-to-that-of/m-p/718831#M222504</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An outstanding move, thank you very much for optimizing my code.&lt;/P&gt;</description>
    <pubDate>Fri, 12 Feb 2021 08:23:39 GMT</pubDate>
    <dc:creator>Phil_NZ</dc:creator>
    <dc:date>2021-02-12T08:23:39Z</dc:date>
    <item>
      <title>Why summary statistic of lag value is identical to that of original variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-summary-statistic-of-lag-value-is-identical-to-that-of/m-p/718777#M222480</link>
      <description>&lt;P&gt;Hi SAS Users,&lt;/P&gt;
&lt;P&gt;Happy Lunar New Year!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This morning I try to perform lag of a variable called "&lt;STRONG&gt;s39&lt;/STRONG&gt;" in my dataset. However, when I do &lt;STRONG&gt;proc means&lt;/STRONG&gt; to cross check, the results seems not properly.&lt;/P&gt;
&lt;P&gt;It is my code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data merge2_fix;
   set merge2_sample;
   lags39=ifn(first.type,.,lag(s39));
   if n(s39,lags39)=2 then
   del_exc_rat= s39-lags39;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;My data is attached below, but I will show a small part here for visualization&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Type	Year	s39
131566	1988	0.0008752604
131566	1989	0.0423339608
131566	1990	0.4875890833
131566	1991	0.9535544167
131566	1992	0.9906416667
131566	1993	0.9989458333
131566	1994	0.9990083333
131566	1995	0.99975
131566	1996	0.9996625
131566	1997	0.9995
131566	1998	0.9995
131566	1999	0.9995
131566	2000	0.9995
131566	2001	0.9995
131566	2002	3.0632566667
131566	2003	2.9006291667
131566	2004	2.9233008189
131566	2005	2.9036575
131566	2006	3.0543133333
131566	2007	3.0956488492
131566	2008	3.1441645599
131566	2009	3.7101068305
131566	2010	3.8962951545
131566	2011	4.1101395762
131566	2012	4.5369343602
131566	2013	5.4593526647
131566	2014	.
131566	2015	.
131566	2016	.
131566	2017	.
131566	2018	.
131566	2019	.
131879	1988	0.0008752604
131879	1989	0.0423339608
131879	1990	0.4875890833
131879	1991	0.9535544167
131879	1992	0.9906416667&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So, Type and Year are character variables when s39 is a numeric variable. The year is from 1988 to 2019.&lt;/P&gt;
&lt;P&gt;From what I performed above, the &lt;STRONG&gt;lag39&lt;/STRONG&gt; variable should have less observation than that of &lt;STRONG&gt;s39&lt;/STRONG&gt;. However, &lt;STRONG&gt;when I run PROC MEANS, the number of observation of these two variables are totally the same&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=merge2_fix n nmiss mean min max;
var s39 lags39 del_exc_rat;
title " Merge2_fix";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The result is here, with the abnormal result is yellowed&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="My97_0-1613083317256.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/54619iF33E27DF8EA3041A/image-size/large?v=v2&amp;amp;px=999" role="button" title="My97_0-1613083317256.png" alt="My97_0-1613083317256.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Could you please help me to sort it out?&lt;/P&gt;
&lt;P&gt;Many thanks and warm regards.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Feb 2021 23:18:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-summary-statistic-of-lag-value-is-identical-to-that-of/m-p/718777#M222480</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-02-11T23:18:42Z</dc:date>
    </item>
    <item>
      <title>Re: Why summary statistic of lag value is identical to that of original variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-summary-statistic-of-lag-value-is-identical-to-that-of/m-p/718779#M222482</link>
      <description>&lt;P&gt;You are attempting to use the First.type without a BY Type statement.&lt;/P&gt;
&lt;P&gt;So First.type is NEVER true.&lt;/P&gt;
&lt;P&gt;The log likely shows:&lt;/P&gt;
&lt;PRE&gt;NOTE: Variable first.type is uninitialized.
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or show the LOG with the Merge2_fix code executed.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Feb 2021 22:52:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-summary-statistic-of-lag-value-is-identical-to-that-of/m-p/718779#M222482</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-02-11T22:52:41Z</dc:date>
    </item>
    <item>
      <title>Re: Why summary statistic of lag value is identical to that of original variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-summary-statistic-of-lag-value-is-identical-to-that-of/m-p/718784#M222484</link>
      <description>Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;,&lt;BR /&gt;&lt;BR /&gt;You are totally correct about that part.</description>
      <pubDate>Thu, 11 Feb 2021 23:20:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-summary-statistic-of-lag-value-is-identical-to-that-of/m-p/718784#M222484</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-02-11T23:20:12Z</dc:date>
    </item>
    <item>
      <title>Re: Why summary statistic of lag value is identical to that of original variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-summary-statistic-of-lag-value-is-identical-to-that-of/m-p/718799#M222487</link>
      <description>&lt;P&gt;BTW, you don't need the lag function if you are really only looking for the deltas:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead of:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  lags39=ifn(first.type,.,lag(s39));
   if n(s39,lags39)=2 then
   del_exc_rat= s39-lags39;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you can&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;del_exc_rat=ifn(first.type,.,dif(s39));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;DIF(x) is defined as X-lag(X).&amp;nbsp; &amp;nbsp;It will not generate notes when S39 and/or lag(S39) is missing.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Feb 2021 01:49:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-summary-statistic-of-lag-value-is-identical-to-that-of/m-p/718799#M222487</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-02-12T01:49:24Z</dc:date>
    </item>
    <item>
      <title>Re: Why summary statistic of lag value is identical to that of original variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-summary-statistic-of-lag-value-is-identical-to-that-of/m-p/718831#M222504</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An outstanding move, thank you very much for optimizing my code.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Feb 2021 08:23:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-summary-statistic-of-lag-value-is-identical-to-that-of/m-p/718831#M222504</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-02-12T08:23:39Z</dc:date>
    </item>
  </channel>
</rss>

