<?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: Extracting the first record per Order in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Extracting-the-first-record-per-Order/m-p/717501#M27512</link>
    <description>&lt;P&gt;If your data is sorted then&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   by id;
   if first.id;
run;&lt;/PRE&gt;
&lt;P&gt;When you use a By statement, which requires the data to be sorted by the variables on the statement and if you mix ascending and descending order you need to provide the same information as Proc Sort would use to sort the values, the data step creates automatic variables to identify the first and last record of each by group. You access the values using First. or Last. (dot immediately after the word first or last and before the variable name). These variables have numeric values of 1 (true) and 0 (false) and so can be used in If statements. The automatic variables are not written to the output data.&lt;/P&gt;
&lt;P&gt;A simple: If &amp;lt;condition&amp;gt;; is known as a "subsetting if" and only records that have a true value for the condition are kept.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW your data step fails to run. You did not tell the input that the values of the variable A are character.&lt;/P&gt;</description>
    <pubDate>Mon, 08 Feb 2021 16:05:00 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-02-08T16:05:00Z</dc:date>
    <item>
      <title>Extracting the first record per Order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extracting-the-first-record-per-Order/m-p/717496#M27510</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data T;
input ID A;
Datalines;
1310 CA
1310 AB&lt;BR /&gt;1310 CD
1320 AB
1320 CA
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;how can I extract only the first encountered records per ID? i.e.&lt;/P&gt;
&lt;P&gt;1310 CA&lt;/P&gt;
&lt;P&gt;1320 AB&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2021 06:34:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extracting-the-first-record-per-Order/m-p/717496#M27510</guid>
      <dc:creator>cmemtsa</dc:creator>
      <dc:date>2021-02-08T06:34:51Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting the first record per Order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extracting-the-first-record-per-Order/m-p/717501#M27512</link>
      <description>&lt;P&gt;If your data is sorted then&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   by id;
   if first.id;
run;&lt;/PRE&gt;
&lt;P&gt;When you use a By statement, which requires the data to be sorted by the variables on the statement and if you mix ascending and descending order you need to provide the same information as Proc Sort would use to sort the values, the data step creates automatic variables to identify the first and last record of each by group. You access the values using First. or Last. (dot immediately after the word first or last and before the variable name). These variables have numeric values of 1 (true) and 0 (false) and so can be used in If statements. The automatic variables are not written to the output data.&lt;/P&gt;
&lt;P&gt;A simple: If &amp;lt;condition&amp;gt;; is known as a "subsetting if" and only records that have a true value for the condition are kept.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW your data step fails to run. You did not tell the input that the values of the variable A are character.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2021 16:05:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extracting-the-first-record-per-Order/m-p/717501#M27512</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-02-08T16:05:00Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting the first record per Order</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extracting-the-first-record-per-Order/m-p/717508#M27514</link>
      <description>Thank you!</description>
      <pubDate>Mon, 08 Feb 2021 08:10:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extracting-the-first-record-per-Order/m-p/717508#M27514</guid>
      <dc:creator>cmemtsa</dc:creator>
      <dc:date>2021-02-08T08:10:41Z</dc:date>
    </item>
  </channel>
</rss>

