<?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: how many is the sum in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/how-many-is-the-sum/m-p/836306#M82105</link>
    <description>I just want to know why.&lt;BR /&gt;You give me the explain. Thank you.</description>
    <pubDate>Sat, 01 Oct 2022 16:18:01 GMT</pubDate>
    <dc:creator>tianerhu</dc:creator>
    <dc:date>2022-10-01T16:18:01Z</dc:date>
    <item>
      <title>how many is the sum</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-many-is-the-sum/m-p/836301#M82100</link>
      <description>&lt;P&gt;dataset is abc: the name of column is A ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A&lt;/P&gt;
&lt;P&gt;4&lt;/P&gt;
&lt;P&gt;5&lt;/P&gt;
&lt;P&gt;6&lt;/P&gt;
&lt;P&gt;if _N_= 3 then sum(lag(A)+lag2(A)+lag3(A) = ______&lt;/P&gt;</description>
      <pubDate>Sat, 01 Oct 2022 15:23:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-many-is-the-sum/m-p/836301#M82100</guid>
      <dc:creator>tianerhu</dc:creator>
      <dc:date>2022-10-01T15:23:11Z</dc:date>
    </item>
    <item>
      <title>Re: how many is the sum</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-many-is-the-sum/m-p/836302#M82101</link>
      <description>&lt;P&gt;Nice trick question.&lt;/P&gt;
&lt;P&gt;Since LAG3 is still missing when the third observation is processed (LAG has the value of the 2nd observation, LAG2 the value of the 1st), the result of the addition is missing, so the SUM function gets only one missing argument, and the result will also be missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But why don't you try it yourself? Too lazy?&lt;/P&gt;</description>
      <pubDate>Sat, 01 Oct 2022 15:43:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-many-is-the-sum/m-p/836302#M82101</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-10-01T15:43:34Z</dc:date>
    </item>
    <item>
      <title>Re: how many is the sum</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-many-is-the-sum/m-p/836303#M82102</link>
      <description>&lt;P&gt;Depends on how you code it.&lt;/P&gt;
&lt;P&gt;Check out this version:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  input A;
  v1 = sum(lag(a)+lag2(a)+lag3(a));
  v2 = sum(lag(a),lag2(a),lag3(a));
  if _n_=3 then v3 = sum(lag(a)+lag2(a)+lag3(a));
  if _n_=3 then v4 = sum(lag(a)+lag2(a)+lag3(a));
  put (_n_ A v1-v4) (=);
cards;
4
5
6
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;9    data test;
10     input A;
11     v1 = sum(lag(a)+lag2(a)+lag3(a));
12     v2 = sum(lag(a),lag2(a),lag3(a));
13     if _n_=3 then v3 = sum(lag(a)+lag2(a)+lag3(a));
14     if _n_=3 then v4 = sum(lag(a)+lag2(a)+lag3(a));
15     put (_n_ A v1-v4) (=);
16     cards;

_N_=1 A=4 v1=. v2=. v3=. v4=.
_N_=2 A=5 v1=. v2=4 v3=. v4=.
_N_=3 A=6 v1=. v2=9 v3=. v4=.
NOTE: Missing values were generated as a result of performing an operation on missing values.
      Each place is given by: (Number of times) at (Line):(Column).
      3 at 11:8    2 at 11:18   3 at 11:26   1 at 12:8    1 at 13:22   1 at 13:32   1 at 13:40   1 at 14:22   1 at 14:32
      1 at 14:40
NOTE: The data set WORK.TEST has 3 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


20     ;
&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;</description>
      <pubDate>Sat, 01 Oct 2022 15:49:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-many-is-the-sum/m-p/836303#M82102</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-10-01T15:49:18Z</dc:date>
    </item>
    <item>
      <title>Re: how many is the sum</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-many-is-the-sum/m-p/836306#M82105</link>
      <description>I just want to know why.&lt;BR /&gt;You give me the explain. Thank you.</description>
      <pubDate>Sat, 01 Oct 2022 16:18:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-many-is-the-sum/m-p/836306#M82105</guid>
      <dc:creator>tianerhu</dc:creator>
      <dc:date>2022-10-01T16:18:01Z</dc:date>
    </item>
    <item>
      <title>Re: how many is the sum</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-many-is-the-sum/m-p/836307#M82106</link>
      <description>Thank you for your help.</description>
      <pubDate>Sat, 01 Oct 2022 16:18:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-many-is-the-sum/m-p/836307#M82106</guid>
      <dc:creator>tianerhu</dc:creator>
      <dc:date>2022-10-01T16:18:46Z</dc:date>
    </item>
  </channel>
</rss>

