<?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: lag in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/lag/m-p/897537#M354675</link>
    <description>&lt;P&gt;You always get this when using lag, because there is not a lagged value for the first observation, so it is set to missing.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 06 Oct 2023 06:04:14 GMT</pubDate>
    <dc:creator>rudfaden</dc:creator>
    <dc:date>2023-10-06T06:04:14Z</dc:date>
    <item>
      <title>lag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/lag/m-p/897532#M354672</link>
      <description>&lt;P&gt;data s;&lt;BR /&gt;input start end;&lt;BR /&gt;cards;&lt;BR /&gt;10 20&lt;BR /&gt;15 40&lt;BR /&gt;25 60&lt;BR /&gt;26 70&lt;BR /&gt;55 85&lt;BR /&gt;40 75&lt;BR /&gt;35 45&lt;BR /&gt;15 60&lt;BR /&gt;25 72&lt;BR /&gt;85 45&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;USing above dataset i want substract current observation of end - next observation of start&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Iam tried below code but iam getting below note :&lt;BR /&gt;"Missing values were generated as a result of performing an operation on missing values.&lt;BR /&gt;Each place is given by: (Number of times) at (Line):(Column)."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data ssol ;&lt;BR /&gt;set s ;&lt;BR /&gt;lag1 = lag(end);&lt;BR /&gt;new = lag1-start ;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2023 04:58:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/lag/m-p/897532#M354672</guid>
      <dc:creator>112211</dc:creator>
      <dc:date>2023-10-06T04:58:22Z</dc:date>
    </item>
    <item>
      <title>Re: lag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/lag/m-p/897537#M354675</link>
      <description>&lt;P&gt;You always get this when using lag, because there is not a lagged value for the first observation, so it is set to missing.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2023 06:04:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/lag/m-p/897537#M354675</guid>
      <dc:creator>rudfaden</dc:creator>
      <dc:date>2023-10-06T06:04:14Z</dc:date>
    </item>
    <item>
      <title>Re: lag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/lag/m-p/897539#M354676</link>
      <description>&lt;P&gt;Based on your description it sounds you're rather after some "look ahead" and not some "look back" logic.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With both look ahead or look back you will always have at least one row (first or last) where the value is missing and though will have an operation with missing values. It's just a SAS Note so nothing wrong with this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If in below code neither variable derived_1 nor derived_2 is what you want then please explain further your desired logic and ideally also provide a table WANT that show us the desired result if using your have table.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input start end;
  cards;
10 20
15 40
25 60
26 70
55 85
40 75
35 45
15 60
25 72
85 45
;

data want;
  merge have have(firstobs=2 keep=start rename=(start=_next_start));
  derived_1 = end-_next_start ;

  _lag_end=lag(end);
  derived_2= _lag_end-start;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1696572507557.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/88686i7218B8D926768C3A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1696572507557.png" alt="Patrick_0-1696572507557.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2023 06:12:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/lag/m-p/897539#M354676</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-10-06T06:12:27Z</dc:date>
    </item>
    <item>
      <title>Re: lag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/lag/m-p/897552#M354687</link>
      <description>&lt;P&gt;Try one of these (mind that results for the first observation differs):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ssol1 ;
set s ;
lag1 = lag(end);
new = sum(lag1,-start);
run;


data ssol2 ;
set s ;
lag1 = lag(end);
if lag1&amp;gt;. then new = sum(lag1,-start);
run;
 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2023 08:37:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/lag/m-p/897552#M354687</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-10-06T08:37:10Z</dc:date>
    </item>
    <item>
      <title>Re: lag</title>
      <link>https://communities.sas.com/t5/SAS-Programming/lag/m-p/897582#M354701</link>
      <description>&lt;P&gt;Conditionally (if/then) processing data can help avoiding such NOTEs in sas log when doing computation on data with missing values;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;eg:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ssol ;
      set s ;
      lag1 = lag(end);
      if lag1 ne . then new = lag1-start;
proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Oct 2023 14:23:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/lag/m-p/897582#M354701</guid>
      <dc:creator>A_Kh</dc:creator>
      <dc:date>2023-10-06T14:23:24Z</dc:date>
    </item>
  </channel>
</rss>

