<?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 last. and output in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/last-and-output/m-p/865231#M341673</link>
    <description>&lt;PRE&gt;data test1;
input apple lemon;
datalines;
4 3
7 80
22 500
;
run;
proc print data=test1;
run;

data fruit;
set test1;
by apple lemon;
if last.apple then output;
run;
proc print data=fruit;
run;&lt;/PRE&gt;
&lt;P&gt;I tried this but cannot see what last. is doing I was expecting only the last entry where apple=22, lemon=500 in dataset fruit, but I am getting fruit exactly same as test1, so what does last. and output do here?&lt;/P&gt;</description>
    <pubDate>Mon, 20 Mar 2023 15:02:06 GMT</pubDate>
    <dc:creator>HeatherNewton</dc:creator>
    <dc:date>2023-03-20T15:02:06Z</dc:date>
    <item>
      <title>last. and output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/last-and-output/m-p/865231#M341673</link>
      <description>&lt;PRE&gt;data test1;
input apple lemon;
datalines;
4 3
7 80
22 500
;
run;
proc print data=test1;
run;

data fruit;
set test1;
by apple lemon;
if last.apple then output;
run;
proc print data=fruit;
run;&lt;/PRE&gt;
&lt;P&gt;I tried this but cannot see what last. is doing I was expecting only the last entry where apple=22, lemon=500 in dataset fruit, but I am getting fruit exactly same as test1, so what does last. and output do here?&lt;/P&gt;</description>
      <pubDate>Mon, 20 Mar 2023 15:02:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/last-and-output/m-p/865231#M341673</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2023-03-20T15:02:06Z</dc:date>
    </item>
    <item>
      <title>Re: last. and output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/last-and-output/m-p/865233#M341674</link>
      <description>&lt;P&gt;When you use &lt;FONT face="courier new,courier"&gt;last.apple&lt;/FONT&gt;, SAS assumes that your data is sorted by APPLE, and so the last record of each value of APPLE will be output. In your trivial example, there is only one record for each value of APPLE, this one record for each value of APPLE is also the last record for each value of APPLE, and so this record is output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If we modify the data&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1;
input apple lemon;
datalines;
4 3
4 7
7 12
7 22
7 80
22 500
;

data fruit;
set test1;
by apple lemon;
if last.apple then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can see now that there are multiple records with each value of APPLE, and the last record of each value of APPLE is output.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Mar 2023 15:08:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/last-and-output/m-p/865233#M341674</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-03-20T15:08:50Z</dc:date>
    </item>
  </channel>
</rss>

