<?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 Output last record in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Output-last-record/m-p/465379#M118699</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to output all variables of the previous record simply?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, let's say a condition met like x = lag1(x) then the goal is to output all variables from the previous record as well as the current record.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;</description>
    <pubDate>Mon, 28 May 2018 02:29:17 GMT</pubDate>
    <dc:creator>markc</dc:creator>
    <dc:date>2018-05-28T02:29:17Z</dc:date>
    <item>
      <title>Output last record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-last-record/m-p/465379#M118699</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to output all variables of the previous record simply?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, let's say a condition met like x = lag1(x) then the goal is to output all variables from the previous record as well as the current record.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;</description>
      <pubDate>Mon, 28 May 2018 02:29:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-last-record/m-p/465379#M118699</guid>
      <dc:creator>markc</dc:creator>
      <dc:date>2018-05-28T02:29:17Z</dc:date>
    </item>
    <item>
      <title>Re: Output last record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-last-record/m-p/465384#M118703</link>
      <description>&lt;P&gt;You can't easily go back except by using POINT=.&lt;/P&gt;
&lt;P&gt;Much better to read ahead,&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE;
   x=1; y=1; output; 
   x=2; y=2; output; 
   x=2; y=3; output;
   x=2; y=4; output;
   x=3; y=5; output;
   x=4; y=6; output;
   x=4; y=7; output;
   x=5; y=8; output;
run; 
data WANT;                                  
  merge HAVE HAVE(firstobs=2 keep=X rename=(X=NEXT_X));      
  if X=NEXT_X then do;
    output; 
    KEEP_NEXT+1;
  end;
  else if KEEP_NEXT then do;
    output;
    KEEP_NEXT=0;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;x y&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;2 2&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;2 3&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;2 4&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;4 6&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;4 7&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 May 2018 02:46:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-last-record/m-p/465384#M118703</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-05-28T02:46:58Z</dc:date>
    </item>
    <item>
      <title>Re: Output last record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-last-record/m-p/465385#M118704</link>
      <description>&lt;P&gt;Depending on your needs, this can be coded in the much more compact:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data WANT;                                  
  set HAVE ;      
  by X;
  if not (first.X and last.X) ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 May 2018 02:49:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-last-record/m-p/465385#M118704</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-05-28T02:49:40Z</dc:date>
    </item>
    <item>
      <title>Re: Output last record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-last-record/m-p/465421#M118712</link>
      <description>&lt;P&gt;You can use the second solution suggested by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt; even if your data are not sorted, just use the NOTSORTED option on your BY statement:&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt;&lt;SPAN&gt; WANT&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="token keyword"&gt;&amp;nbsp; set&lt;/SPAN&gt;&lt;SPAN&gt; HAVE &lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="token statement"&gt;&amp;nbsp; by&lt;/SPAN&gt;&lt;SPAN&gt; X notsorted&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="token keyword"&gt;&amp;nbsp; if&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;not&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;first&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;X and last&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;X&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 28 May 2018 08:13:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-last-record/m-p/465421#M118712</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-05-28T08:13:19Z</dc:date>
    </item>
  </channel>
</rss>

