<?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 Understanding a data step in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Understanding-a-data-step/m-p/884151#M39243</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data Db_1;
set Db;
by variable_order;
if first.variable=1 then amount=0;
amount+balance;
if last.variable=1 then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hi, on the code as above i can't understand the use of first and last. Are they simply libraries or have they a specific function?&lt;/P&gt;</description>
    <pubDate>Mon, 10 Jul 2023 07:15:11 GMT</pubDate>
    <dc:creator>ari2495</dc:creator>
    <dc:date>2023-07-10T07:15:11Z</dc:date>
    <item>
      <title>Understanding a data step</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Understanding-a-data-step/m-p/884151#M39243</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data Db_1;
set Db;
by variable_order;
if first.variable=1 then amount=0;
amount+balance;
if last.variable=1 then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hi, on the code as above i can't understand the use of first and last. Are they simply libraries or have they a specific function?&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2023 07:15:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Understanding-a-data-step/m-p/884151#M39243</guid>
      <dc:creator>ari2495</dc:creator>
      <dc:date>2023-07-10T07:15:11Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding a data step</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Understanding-a-data-step/m-p/884153#M39244</link>
      <description>&lt;P&gt;The FIRST. and LAST. are automatic variables, created for every variable used in the BY statement. They indicate a change in the values of a variable. See this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input x;
datalines;
1
1
1
2
2
3
;

data want;
set have;
by x;
f = first.x;
l = last.x;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;BTW, your data step will not work, as you use FIRST. and LAST. for a variable not included in the BY.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also note that, for BY to work, the dataset must be sorted by the variable(s), unless the NOTSORTED option is used.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2023 07:55:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Understanding-a-data-step/m-p/884153#M39244</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-07-10T07:55:38Z</dc:date>
    </item>
  </channel>
</rss>

