<?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 pull records with the last n number of dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-pull-records-with-the-last-n-number-of-dates/m-p/438571#M109364</link>
    <description>&lt;P&gt;The problem is your using SQL, which is not built with postional rows in mind, only logical clauses.&amp;nbsp; Switch to using SAS (it is the language you are programming in for instance) and it is a simple problem:&lt;/P&gt;
&lt;PRE&gt;proc sort data=sasuser.quarter out=distinctq;
  by quarter descending desc;
run;
data want;
  set distinctq;
  by quarter;
  c=ifn(first.quater,1,c+1);
  if c &amp;lt;= 3 then output;
run;&lt;/PRE&gt;</description>
    <pubDate>Tue, 20 Feb 2018 09:06:55 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2018-02-20T09:06:55Z</dc:date>
    <item>
      <title>How to pull records with the last n number of dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pull-records-with-the-last-n-number-of-dates/m-p/438566#M109363</link>
      <description>&lt;P&gt;Good day.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm struggling with the problem of creating a report with the last 3 dates that is in my data set. So I should not hard code the dates that I want in the report,&amp;nbsp;the dates&amp;nbsp;should be determined by the data set itself. I've tried using proc sql to get the distinct dates that is present in my data set so I can use the latest 3 dates present, but I can't seem to figure out how to extract only the records with those dates from my data set. the code I used to get the distinct dates is:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
create table DISTINCTQ as
    select distinct QUARTER
        from SASUSER.QUARTER
            order by QUARTER DESC;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Feb 2018 09:02:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pull-records-with-the-last-n-number-of-dates/m-p/438566#M109363</guid>
      <dc:creator>HelpPlease</dc:creator>
      <dc:date>2018-02-20T09:02:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to pull records with the last n number of dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pull-records-with-the-last-n-number-of-dates/m-p/438571#M109364</link>
      <description>&lt;P&gt;The problem is your using SQL, which is not built with postional rows in mind, only logical clauses.&amp;nbsp; Switch to using SAS (it is the language you are programming in for instance) and it is a simple problem:&lt;/P&gt;
&lt;PRE&gt;proc sort data=sasuser.quarter out=distinctq;
  by quarter descending desc;
run;
data want;
  set distinctq;
  by quarter;
  c=ifn(first.quater,1,c+1);
  if c &amp;lt;= 3 then output;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Feb 2018 09:06:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pull-records-with-the-last-n-number-of-dates/m-p/438571#M109364</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-02-20T09:06:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to pull records with the last n number of dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pull-records-with-the-last-n-number-of-dates/m-p/438579#M109367</link>
      <description>&lt;P&gt;I think this is headed in the right direction.&amp;nbsp; Here are a couple of changes I would recommend:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=have out=temp;&lt;/P&gt;
&lt;P&gt;by descending quarter;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set temp;&lt;/P&gt;
&lt;P&gt;by descending quarter;&lt;/P&gt;
&lt;P&gt;n_dates + first.quarter;&lt;/P&gt;
&lt;P&gt;if n_dates &amp;gt; 3 then stop;&lt;/P&gt;
&lt;P&gt;drop n_dates;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's not clear how large your data set, and how important efficiency considerations would be.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Feb 2018 09:22:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pull-records-with-the-last-n-number-of-dates/m-p/438579#M109367</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-20T09:22:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to pull records with the last n number of dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-pull-records-with-the-last-n-number-of-dates/m-p/438581#M109368</link>
      <description>thanks a lot! it worked perfectly.</description>
      <pubDate>Tue, 20 Feb 2018 09:25:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-pull-records-with-the-last-n-number-of-dates/m-p/438581#M109368</guid>
      <dc:creator>HelpPlease</dc:creator>
      <dc:date>2018-02-20T09:25:55Z</dc:date>
    </item>
  </channel>
</rss>

