<?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: Output first record of each member in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Output-first-record-of-each-member/m-p/736299#M229344</link>
    <description>&lt;P&gt;The very best programmers in the world will always look at the log to see what went wrong.&amp;nbsp; If you want help, you should post the log.&lt;/P&gt;</description>
    <pubDate>Thu, 22 Apr 2021 00:53:19 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2021-04-22T00:53:19Z</dc:date>
    <item>
      <title>Output first record of each member</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-first-record-of-each-member/m-p/736294#M229342</link>
      <description>&lt;P&gt;I want the first record of each member only.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=billfinal; by contract bill_end descend;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data billfinal2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;set billfinal;&lt;/P&gt;&lt;P&gt;by&amp;nbsp;contract bill_end;&lt;/P&gt;&lt;P&gt;if first.contract and last.contract then output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;I get back an empty dataset;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I&amp;nbsp; removed the last.contract and than i only get 1 row of data.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i am not sure what i am doing wrong to get the first record of each different contract.&amp;nbsp; a contract can have multiple rows due to the bill date but i only want the last one.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Apr 2021 23:46:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-first-record-of-each-member/m-p/736294#M229342</guid>
      <dc:creator>bibbnd</dc:creator>
      <dc:date>2021-04-21T23:46:07Z</dc:date>
    </item>
    <item>
      <title>Re: Output first record of each member</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-first-record-of-each-member/m-p/736298#M229343</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/149821"&gt;@bibbnd&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I want the first record of each member only.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=billfinal; by contract bill_end descend;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data billfinal2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;set billfinal;&lt;/P&gt;
&lt;P&gt;by&amp;nbsp;contract bill_end;&lt;/P&gt;
&lt;P&gt;if first.contract and last.contract then output;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;I get back an empty dataset;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I&amp;nbsp; removed the last.contract and than i only get 1 row of data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i am not sure what i am doing wrong to get the first record of each different contract.&amp;nbsp; a contract can have multiple rows due to the bill date but i only want the last one.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So why do you include "First.contract"? First and last for a single variable are true when there is only one value of a by variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you try " if last.contract then output;" ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may also need to check your sort order. What does your log show? It is very possible that your sort failed unless you have a variable named "descend" in the data if that is the sort code you showed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Apr 2021 00:47:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-first-record-of-each-member/m-p/736298#M229343</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-04-22T00:47:31Z</dc:date>
    </item>
    <item>
      <title>Re: Output first record of each member</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-first-record-of-each-member/m-p/736299#M229344</link>
      <description>&lt;P&gt;The very best programmers in the world will always look at the log to see what went wrong.&amp;nbsp; If you want help, you should post the log.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Apr 2021 00:53:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-first-record-of-each-member/m-p/736299#M229344</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-04-22T00:53:19Z</dc:date>
    </item>
    <item>
      <title>Re: Output first record of each member</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-first-record-of-each-member/m-p/736312#M229355</link>
      <description>&lt;P&gt;If you only want the last one row, you can change this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if first.contract and last.contract then output;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if last.contract then output;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if last.contract;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As for the sort order, as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;already mentioned, check if descend is a variable or if it is intended for descending order.&lt;BR /&gt;If you want to sort in descending order, put "descending" before the variable name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=billfinal;
  by contract descending bill_end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want everything to be in descending order, you can use the key statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=billfinal; 
  key contract descending / descending;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Apr 2021 02:53:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-first-record-of-each-member/m-p/736312#M229355</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2021-04-22T02:53:59Z</dc:date>
    </item>
    <item>
      <title>Re: Output first record of each member</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-first-record-of-each-member/m-p/736329#M229369</link>
      <description>there is no log. it just output the first row of the dataset and not the other records</description>
      <pubDate>Thu, 22 Apr 2021 05:28:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-first-record-of-each-member/m-p/736329#M229369</guid>
      <dc:creator>bibbnd</dc:creator>
      <dc:date>2021-04-22T05:28:26Z</dc:date>
    </item>
    <item>
      <title>Re: Output first record of each member</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-first-record-of-each-member/m-p/736348#M229375</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/149821"&gt;@bibbnd&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;there is no log. it just output the first row of the dataset and not the other records&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;There is ALWAYS a log unless SAS has crashed or nothing was submitted at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See this example code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input contract $ bill_end :yymmdd10.;
format bill_end yymmdd10.;
datalines;
A 2020-02-03
A 2021-01-01
B 2021-01-01
B 2021-02-01
;

proc sort data=have;
by contract descending bill_end;
run;

data want;
set have;
by contract;
if first.contract;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and the log from it when it is submitted:&lt;/P&gt;
&lt;PRE&gt; 73         data have;
 74         input contract $ bill_end :yymmdd10.;
 75         format bill_end yymmdd10.;
 76         datalines;
 
 NOTE: The data set WORK.HAVE has 4 observations and 2 variables.
 NOTE:  Verwendet wurde: DATA statement - (Gesamtverarbeitungszeit):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 
 81         ;
 82         
 83         proc sort data=have;
 84         by contract descending bill_end;
 85         run;
 
 NOTE: There were 4 observations read from the data set WORK.HAVE.
 NOTE: The data set WORK.HAVE has 4 observations and 2 variables.
 NOTE:  Verwendet wurde: PROZEDUR SORT - (Gesamtverarbeitungszeit):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 
 86         
 87         data want;
 88         set have;
 89         by contract;
 90         if first.contract;
 91         run;
 
 NOTE: There were 4 observations read from the data set WORK.HAVE.
 NOTE: The data set WORK.WANT has 2 observations and 2 variables.
 NOTE:  Verwendet wurde: DATA statement - (Gesamtverarbeitungszeit):
       real time           0.00 seconds
       cpu time            0.00 seconds
&lt;/PRE&gt;
&lt;P&gt;For further help, provide example data in a data step with datalines (see above,&amp;nbsp;&lt;STRONG&gt;do not skip this!&lt;/STRONG&gt;), so we can provide code that works with the data as posted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Apr 2021 08:45:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-first-record-of-each-member/m-p/736348#M229375</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-04-22T08:45:02Z</dc:date>
    </item>
  </channel>
</rss>

