<?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: Assigning a variable value in the last record to a new variable. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Assigning-a-variable-value-in-the-last-record-to-a-new-variable/m-p/76692#M16588</link>
    <description>Is it absolutely necessary to have the data sorted in a ascending order?&lt;BR /&gt;
&lt;BR /&gt;
Normally you just need the data sorted, reversing to descending would simplify greatly the solution by reducing it to a single pass.&lt;BR /&gt;
&lt;BR /&gt;
Assuming that YEAR is numeric:&lt;BR /&gt;
&lt;BR /&gt;
data RESULTS;&lt;BR /&gt;
set DATA;&lt;BR /&gt;
if _N_ eq 1 then call symput('MAX_YEAR',put(YEAR,best.));&lt;BR /&gt;
if not (YEAR &amp;gt;= symgetn('MAX_YEAR') -4) then stop;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Cheers from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;</description>
    <pubDate>Mon, 26 Oct 2009 15:49:55 GMT</pubDate>
    <dc:creator>DanielSantos</dc:creator>
    <dc:date>2009-10-26T15:49:55Z</dc:date>
    <item>
      <title>Assigning a variable value in the last record to a new variable.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assigning-a-variable-value-in-the-last-record-to-a-new-variable/m-p/76690#M16586</link>
      <description>I have a SAS table, MYTABLE, with the variable YEAR, among others. The table is sorted by YEAR in ascending order.&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;The last(highest) YEAR is supposed not to be known in advance.&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
 Since the ascending order by YEAR, I know that the value of YEAR (at least) in the last record contains the last(highest) YEAR.&lt;BR /&gt;
&lt;BR /&gt;
I want to keep all the records for the last 5 years. If I could assign the value of YEAR in the last record to a variable LASTYEAR I could have the  condition&lt;BR /&gt;
&lt;BR /&gt;
IF YEAR &amp;gt;= LASTYEAR - 4; .&lt;BR /&gt;
&lt;BR /&gt;
I would prefere to do this in one data step, but two data steps would be OK. I don't want to use PROC SQL.&lt;BR /&gt;
&lt;BR /&gt;
Is this possible?</description>
      <pubDate>Mon, 26 Oct 2009 08:21:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assigning-a-variable-value-in-the-last-record-to-a-new-variable/m-p/76690#M16586</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-10-26T08:21:27Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning a variable value in the last record to a new variable.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assigning-a-variable-value-in-the-last-record-to-a-new-variable/m-p/76691#M16587</link>
      <description>[pre]&lt;BR /&gt;
data allWithLastAge;&lt;BR /&gt;
   set sashelp.class(keep=age rename=age=target) point=nobs nobs=nobs;&lt;BR /&gt;
   put target=;&lt;BR /&gt;
   do until(eof);&lt;BR /&gt;
      set sashelp.class end=eof;&lt;BR /&gt;
      if age eq target then output;&lt;BR /&gt;
      end;&lt;BR /&gt;
   stop;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Mon, 26 Oct 2009 12:12:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assigning-a-variable-value-in-the-last-record-to-a-new-variable/m-p/76691#M16587</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-10-26T12:12:33Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning a variable value in the last record to a new variable.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assigning-a-variable-value-in-the-last-record-to-a-new-variable/m-p/76692#M16588</link>
      <description>Is it absolutely necessary to have the data sorted in a ascending order?&lt;BR /&gt;
&lt;BR /&gt;
Normally you just need the data sorted, reversing to descending would simplify greatly the solution by reducing it to a single pass.&lt;BR /&gt;
&lt;BR /&gt;
Assuming that YEAR is numeric:&lt;BR /&gt;
&lt;BR /&gt;
data RESULTS;&lt;BR /&gt;
set DATA;&lt;BR /&gt;
if _N_ eq 1 then call symput('MAX_YEAR',put(YEAR,best.));&lt;BR /&gt;
if not (YEAR &amp;gt;= symgetn('MAX_YEAR') -4) then stop;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Cheers from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;</description>
      <pubDate>Mon, 26 Oct 2009 15:49:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assigning-a-variable-value-in-the-last-record-to-a-new-variable/m-p/76692#M16588</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2009-10-26T15:49:55Z</dc:date>
    </item>
  </channel>
</rss>

