<?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: How to select first and last row of a data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-first-and-last-row-of-a-data/m-p/132580#M260728</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Hi desireatem,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can try this to get last record&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;data KSm_&amp;amp;p(rename=survival1=(survival_max time=time_max));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;set Kaplan_&amp;amp;p &lt;STRONG&gt;nobs=nobs;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;if _n_ =nobs then keep=&lt;/SPAN&gt;&lt;STRONG style="font-family: 'Courier New'; background: white; color: teal; font-size: 10pt;"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;if keep ne &lt;/SPAN&gt;&lt;STRONG style="font-family: 'Courier New'; background: white; color: teal; font-size: 10pt;"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; then delete;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;drop keep survival;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;Sam&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 12 Jul 2013 14:25:53 GMT</pubDate>
    <dc:creator>sam369</dc:creator>
    <dc:date>2013-07-12T14:25:53Z</dc:date>
    <item>
      <title>How to select first and last row of a data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-first-and-last-row-of-a-data/m-p/132579#M260727</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;The first pick&amp;nbsp; the first row from the data set kaplan.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;How come the statement _n_=n does not pick the last row.?&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;How do I pick the last row?&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;data KS_;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;set Kaplan;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;if _n_ =&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; then keep=&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;if keep ne &lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; then delete;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;drop keep survival;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;data KSm_&amp;amp;p(rename=survival1=(survival_max time=time_max));&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;set Kaplan_&amp;amp;p;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;if _n_ =n then keep=&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;if keep ne &lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; then delete;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;drop keep survival;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Jul 2013 14:09:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-first-and-last-row-of-a-data/m-p/132579#M260727</guid>
      <dc:creator>desireatem</dc:creator>
      <dc:date>2013-07-12T14:09:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to select first and last row of a data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-first-and-last-row-of-a-data/m-p/132580#M260728</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Hi desireatem,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can try this to get last record&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;data KSm_&amp;amp;p(rename=survival1=(survival_max time=time_max));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;set Kaplan_&amp;amp;p &lt;STRONG&gt;nobs=nobs;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;if _n_ =nobs then keep=&lt;/SPAN&gt;&lt;STRONG style="font-family: 'Courier New'; background: white; color: teal; font-size: 10pt;"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;if keep ne &lt;/SPAN&gt;&lt;STRONG style="font-family: 'Courier New'; background: white; color: teal; font-size: 10pt;"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt; then delete;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;drop keep survival;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 10pt;"&gt;Sam&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Jul 2013 14:25:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-first-and-last-row-of-a-data/m-p/132580#M260728</guid>
      <dc:creator>sam369</dc:creator>
      <dc:date>2013-07-12T14:25:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to select first and last row of a data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-first-and-last-row-of-a-data/m-p/132581#M260729</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;example:&lt;/P&gt;&lt;P&gt;data first_last;&lt;/P&gt;&lt;P&gt;set sashelp.class nobs=nobs;&lt;/P&gt;&lt;P&gt;if _n_ =1 or _n_=nobs;&lt;/P&gt;&lt;P&gt;proc print;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Obs&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Sex&amp;nbsp;&amp;nbsp;&amp;nbsp; Age&amp;nbsp;&amp;nbsp;&amp;nbsp; Height&amp;nbsp;&amp;nbsp;&amp;nbsp; Weight&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Alfred&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; M&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 14&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 69.0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 112.5&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; William&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; M&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 15&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 66.5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 112.0&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Linlin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Jul 2013 14:32:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-first-and-last-row-of-a-data/m-p/132581#M260729</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2013-07-12T14:32:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to select first and last row of a data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-first-and-last-row-of-a-data/m-p/132582#M260730</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If your data set is large, you can skip reading the middle of it:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set have nobs=_nobs_;&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;set have point=_nobs_;&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;stop;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Jul 2013 14:42:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-first-and-last-row-of-a-data/m-p/132582#M260730</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2013-07-12T14:42:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to select first and last row of a data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-first-and-last-row-of-a-data/m-p/132583#M260731</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Need to watch for when NOBS=1 .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data class ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; set sashelp.class (obs=1);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data first_last ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; retain point 1 ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; set class point=point nobs=nobs ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; output;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; if point = nobs then stop;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; else point = nobs ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Jul 2013 17:27:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-first-and-last-row-of-a-data/m-p/132583#M260731</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-07-12T17:27:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to select first and last row of a data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-first-and-last-row-of-a-data/m-p/132584#M260732</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Get the last row with the the END option in the SET statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want; set sashelp.class end=eof;&lt;/P&gt;&lt;P&gt;if eof then output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;EOF is short for end of file.&amp;nbsp; Programmers like to use this term, but you can put whatever you want here.&amp;nbsp; For example, this would also work:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want2; set sashelp.class end=awesome;&lt;/P&gt;&lt;P&gt;if awesome then output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Jul 2013 16:37:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-first-and-last-row-of-a-data/m-p/132584#M260732</guid>
      <dc:creator>jaredp</dc:creator>
      <dc:date>2013-07-15T16:37:37Z</dc:date>
    </item>
  </channel>
</rss>

