<?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 Why am I getting a missing value message? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Why-am-I-getting-a-missing-value-message/m-p/901827#M356382</link>
    <description>&lt;P&gt;27 data a;&lt;BR /&gt;28 input x 1. y 1.;&lt;BR /&gt;29 list;&lt;BR /&gt;30 datalines;&lt;/P&gt;&lt;P&gt;RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0&lt;BR /&gt;31 11&lt;BR /&gt;32 43&lt;BR /&gt;33 43&lt;BR /&gt;NOTE: The data set WORK.A has 3 observations and 2 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.01 seconds&lt;BR /&gt;cpu time 0.03 seconds&lt;BR /&gt;&lt;BR /&gt;34 ;&lt;/P&gt;&lt;P&gt;35 run;&lt;BR /&gt;36&lt;BR /&gt;37 data b;&lt;BR /&gt;38 set a;&lt;BR /&gt;39 by x y;&lt;BR /&gt;40 /*only do the comparison after the first record*/&lt;BR /&gt;41 if _n_=1 then do;&lt;BR /&gt;42 cnt=1;&lt;BR /&gt;43 end;&lt;BR /&gt;44 else do;&lt;BR /&gt;45 if x=lag(x) and y le (lag(y)+4) then cnt+0;&lt;BR /&gt;46 else cnt+1;&lt;BR /&gt;47 end;&lt;BR /&gt;48 run;&lt;/P&gt;&lt;P&gt;2 The SAS System 15:20 Monday, November 6, 2023&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;NOTE: Missing values were generated as a result of performing an operation on missing values.&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Each place is given by: (Number of times) at (Line):(Column).&lt;/STRONG&gt;&lt;BR /&gt;1 at 45:31&lt;BR /&gt;NOTE: There were 3 observations read from the data set WORK.A.&lt;BR /&gt;NOTE: The data set WORK.B has 3 observations and 3 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;/P&gt;</description>
    <pubDate>Mon, 06 Nov 2023 23:46:58 GMT</pubDate>
    <dc:creator>Batman</dc:creator>
    <dc:date>2023-11-06T23:46:58Z</dc:date>
    <item>
      <title>Why am I getting a missing value message?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-am-I-getting-a-missing-value-message/m-p/901827#M356382</link>
      <description>&lt;P&gt;27 data a;&lt;BR /&gt;28 input x 1. y 1.;&lt;BR /&gt;29 list;&lt;BR /&gt;30 datalines;&lt;/P&gt;&lt;P&gt;RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0&lt;BR /&gt;31 11&lt;BR /&gt;32 43&lt;BR /&gt;33 43&lt;BR /&gt;NOTE: The data set WORK.A has 3 observations and 2 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.01 seconds&lt;BR /&gt;cpu time 0.03 seconds&lt;BR /&gt;&lt;BR /&gt;34 ;&lt;/P&gt;&lt;P&gt;35 run;&lt;BR /&gt;36&lt;BR /&gt;37 data b;&lt;BR /&gt;38 set a;&lt;BR /&gt;39 by x y;&lt;BR /&gt;40 /*only do the comparison after the first record*/&lt;BR /&gt;41 if _n_=1 then do;&lt;BR /&gt;42 cnt=1;&lt;BR /&gt;43 end;&lt;BR /&gt;44 else do;&lt;BR /&gt;45 if x=lag(x) and y le (lag(y)+4) then cnt+0;&lt;BR /&gt;46 else cnt+1;&lt;BR /&gt;47 end;&lt;BR /&gt;48 run;&lt;/P&gt;&lt;P&gt;2 The SAS System 15:20 Monday, November 6, 2023&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;NOTE: Missing values were generated as a result of performing an operation on missing values.&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Each place is given by: (Number of times) at (Line):(Column).&lt;/STRONG&gt;&lt;BR /&gt;1 at 45:31&lt;BR /&gt;NOTE: There were 3 observations read from the data set WORK.A.&lt;BR /&gt;NOTE: The data set WORK.B has 3 observations and 3 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;/P&gt;</description>
      <pubDate>Mon, 06 Nov 2023 23:46:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-am-I-getting-a-missing-value-message/m-p/901827#M356382</guid>
      <dc:creator>Batman</dc:creator>
      <dc:date>2023-11-06T23:46:58Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I getting a missing value message?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-am-I-getting-a-missing-value-message/m-p/901830#M356383</link>
      <description>&lt;P&gt;Please note that the lag() function only queues a value if it executes. Using this function conditionally leads most of the time to undesired results.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1699315771008.png" style="width: 776px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/89470iC248CFEF318BD055/image-dimensions/776x64?v=v2" width="776" height="64" role="button" title="Patrick_0-1699315771008.png" alt="Patrick_0-1699315771008.png" /&gt;&lt;/span&gt;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/n0l66p5oqex1f2n1quuopdvtcjqb.htm" target="_blank" rel="noopener"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/n0l66p5oqex1f2n1quuopdvtcjqb.htm&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You get the missing note because the first time below code executes the lag() function will return a missing.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_1-1699315880523.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/89471i6327938D6823CEB1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_1-1699315880523.png" alt="Patrick_1-1699315880523.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I believe logic like below should return what you're after.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data b(drop=_:);
  set a;
  by x y;
  _lag_y=lag(y);
  /*only do the comparison after the first record*/
  if _n_=1 then
    do;
      cnt=1;
    end;
  else
    do;
      if not first.x and y le (_lag_y+4) then cnt+0;
      else cnt+1;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;And stripping down your logic further below should still return the same result:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data b(drop=_:);
  set a;
  by x y;
  _lag_y=lag(y);
  if first.x or y le (_lag_y+4) then cnt+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And even below would still work&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data b(drop=_:);
  set a;
  by x y;
  cnt + ( first.x or y &amp;gt; sum(lag(y),4) );
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Nov 2023 00:31:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-am-I-getting-a-missing-value-message/m-p/901830#M356383</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-11-07T00:31:44Z</dc:date>
    </item>
  </channel>
</rss>

