<?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: Filter to previous month - SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Filter-to-previous-month-SQL/m-p/743331#M232708</link>
    <description>&lt;P&gt;Do you want the previous month counted from today, or from the max date in the dataset?&lt;/P&gt;
&lt;P&gt;Anyway, see here:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table WANT as
  select distinct
    id as id 
    , max(date) format=ddmmyy10.
  from have
  where date between intnx('month',today,-1,'b') and intnx('month',today(),-1,'e')
  group by id
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 24 May 2021 10:27:19 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-05-24T10:27:19Z</dc:date>
    <item>
      <title>Filter to previous month - SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filter-to-previous-month-SQL/m-p/743316#M232700</link>
      <description>&lt;P&gt;I need to add a filter that would grab only data from the previous month.&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code is the following:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table WANT as
select distinct id as id 
, max(date) format=ddmmyy10.
from have
where date between "01Apr2021"d and "31Apr2021"d
group by id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;As you can see it's pretty simple, but I would like to not have the dates hardcoded so it can be run automatically.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to grab all distinct ID from HAVE from the previous month&lt;/P&gt;</description>
      <pubDate>Mon, 24 May 2021 08:58:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filter-to-previous-month-SQL/m-p/743316#M232700</guid>
      <dc:creator>catkat96</dc:creator>
      <dc:date>2021-05-24T08:58:42Z</dc:date>
    </item>
    <item>
      <title>Re: Filter to previous month - SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filter-to-previous-month-SQL/m-p/743331#M232708</link>
      <description>&lt;P&gt;Do you want the previous month counted from today, or from the max date in the dataset?&lt;/P&gt;
&lt;P&gt;Anyway, see here:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table WANT as
  select distinct
    id as id 
    , max(date) format=ddmmyy10.
  from have
  where date between intnx('month',today,-1,'b') and intnx('month',today(),-1,'e')
  group by id
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 May 2021 10:27:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filter-to-previous-month-SQL/m-p/743331#M232708</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-05-24T10:27:19Z</dc:date>
    </item>
    <item>
      <title>Re: Filter to previous month - SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filter-to-previous-month-SQL/m-p/743402#M232743</link>
      <description>&lt;P&gt;To extract all the data from the previous month into table WANT:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table WANT as
select * 
from have
where date between intnx("month", today(), -1, "beginning") and intnx("month", today(), -1, "end");
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 May 2021 17:12:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filter-to-previous-month-SQL/m-p/743402#M232743</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2021-05-24T17:12:01Z</dc:date>
    </item>
    <item>
      <title>Re: Filter to previous month - SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Filter-to-previous-month-SQL/m-p/743405#M232746</link>
      <description>&lt;P&gt;Note, if you want to process the extracted data further, you might be better to create a view instead of a table ( create view WANT as ... ) and then access that view in a subsequent query (create table meanProfits as select id, mean(profit) as meanProfit from WANT group by id; )&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 May 2021 17:17:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Filter-to-previous-month-SQL/m-p/743405#M232746</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2021-05-24T17:17:48Z</dc:date>
    </item>
  </channel>
</rss>

