<?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: Select Data Based on Recent Two Months in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Select-Data-Based-on-Recent-Two-Months/m-p/490468#M128319</link>
    <description>&lt;P&gt;Add&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where intnx("month",mdy(month, 1, Year),-2, "b") &amp;lt; datepart(today());&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;as a where clause. I assume you do not have an actual date variable since you use Year and Month in your code?&lt;/P&gt;</description>
    <pubDate>Tue, 28 Aug 2018 14:10:57 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2018-08-28T14:10:57Z</dc:date>
    <item>
      <title>Select Data Based on Recent Two Months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-Data-Based-on-Recent-Two-Months/m-p/490456#M128313</link>
      <description>&lt;P&gt;I have the following in a macro loop that works as I want it:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
    	CREATE TABLE EGTASK.LATESTA_OAG_&amp;amp;aerodrome._ALL AS 
    	SELECT ("&amp;amp;aerodrome") AS Airport, 
               t1.Year, 
               t1.Month, 
               t1.&amp;amp;aerodrome._OAG_PERCENT AS OAG_PERCENT_ALL
        FROM EGTASK.TAM_TWRS_OAG_PERCENT_F_ALL t1
    	WHERE t1.Year = &amp;amp;curryear AND t1.Month = &amp;amp;currmonth;
    QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please note the WHERE step.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like to modify this so that the final output always gives that last two months of data. For example, if it is run today, August 28 2018, the output will give the last two FULL months, which would be June and July of 2018.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This would be tricky for January and February, which would reference months in the previous year. Could intnx solve this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2018 13:50:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-Data-Based-on-Recent-Two-Months/m-p/490456#M128313</guid>
      <dc:creator>BCNAV</dc:creator>
      <dc:date>2018-08-28T13:50:29Z</dc:date>
    </item>
    <item>
      <title>Re: Select Data Based on Recent Two Months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-Data-Based-on-Recent-Two-Months/m-p/490464#M128316</link>
      <description>&lt;P&gt;Yes, intnx would be better:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table egtask.latesta_oag_&amp;amp;aerodrome._all as 
  select "&amp;amp;aerodrome" as airport, 
         year, 
         month, 
         &amp;amp;aerodrome._oag_percent as oag_percent_all
  from   egtask.tam_twrs_oag_percent_f_all
  where intnx('month',date,-2) &amp;lt; datepart(today());
quit;&lt;/PRE&gt;
&lt;P&gt;Note how I don't shout my code at you.&amp;nbsp; Now intnx uses dates, as having year an month only will be trickier to handle (as you say going over the year for instance).&amp;nbsp; I would avoid having year and month parts in both the data and in macro variables.&amp;nbsp; Create an actual date variable which will allow you check to do these calculations easier, even if you just default day=1 in.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2018 14:08:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-Data-Based-on-Recent-Two-Months/m-p/490464#M128316</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-08-28T14:08:29Z</dc:date>
    </item>
    <item>
      <title>Re: Select Data Based on Recent Two Months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-Data-Based-on-Recent-Two-Months/m-p/490468#M128319</link>
      <description>&lt;P&gt;Add&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where intnx("month",mdy(month, 1, Year),-2, "b") &amp;lt; datepart(today());&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;as a where clause. I assume you do not have an actual date variable since you use Year and Month in your code?&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2018 14:10:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-Data-Based-on-Recent-Two-Months/m-p/490468#M128319</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-08-28T14:10:57Z</dc:date>
    </item>
    <item>
      <title>Re: Select Data Based on Recent Two Months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-Data-Based-on-Recent-Two-Months/m-p/490484#M128328</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;There's several best practices that recommend that designated words (SELECT, FROM, INNER JOIN etc.) are all caps and all variables and table names are lower case to differentiate between the two. Especially in SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2018 14:40:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-Data-Based-on-Recent-Two-Months/m-p/490484#M128328</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-08-28T14:40:40Z</dc:date>
    </item>
    <item>
      <title>Re: Select Data Based on Recent Two Months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-Data-Based-on-Recent-Two-Months/m-p/490498#M128334</link>
      <description>&lt;P&gt;How about actually store date information as SAS date values instead of year/ month (and possibly day of month)?&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2018 14:57:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-Data-Based-on-Recent-Two-Months/m-p/490498#M128334</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-08-28T14:57:39Z</dc:date>
    </item>
    <item>
      <title>Re: Select Data Based on Recent Two Months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-Data-Based-on-Recent-Two-Months/m-p/490511#M128338</link>
      <description>&lt;P&gt;The reason why there is no day value is because these are aggregated monthly counts at air traffic control towers. Only monthly data is required, hence no date field is provided to me of individual flights. I can make one via:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;mdy(t1.Month,1,t1.Year) with a format of MMDDYY8.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now, when I use: intnx('month',t1.date,-2) &amp;lt; datepart(today()); Nothing is returned&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data now looks like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Airport	Date	        Year	Month	Count
CYXX	1/1/2018	2018	1	5,091
CYXX	2/1/2018	2018	2	6,148
CYXX	3/1/2018	2018	3	11,069
CYXX	4/1/2018	2018	4	11,359
CYXX	5/1/2018	2018	5	14,552
CYXX	6/1/2018	2018	6	11,333
CYXX	7/1/2018	2018	7	7,842&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I only want the last two months ever sent out. As can been seen above, that is June and July.&lt;/P&gt;&lt;P&gt;If I use intnx('month',t1.date,-2) &amp;lt; today();&amp;nbsp;then everything is returned.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I suspect this is close...&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2018 15:15:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-Data-Based-on-Recent-Two-Months/m-p/490511#M128338</guid>
      <dc:creator>BCNAV</dc:creator>
      <dc:date>2018-08-28T15:15:33Z</dc:date>
    </item>
    <item>
      <title>Re: Select Data Based on Recent Two Months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-Data-Based-on-Recent-Two-Months/m-p/490525#M128346</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATE between&amp;nbsp; 
                  /*two full months ago, start*/&amp;nbsp;
                  intnx('month', today(), -3, 'b') 
           and
                  /*last month last day*/
                  intnx('month', today(), -1, 'e');&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Aug 2018 15:49:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-Data-Based-on-Recent-Two-Months/m-p/490525#M128346</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-08-28T15:49:47Z</dc:date>
    </item>
    <item>
      <title>Re: Select Data Based on Recent Two Months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-Data-Based-on-Recent-Two-Months/m-p/490526#M128347</link>
      <description>&lt;P&gt;Yep, SAS pushes out a lot of the bad practices as well, missing dots at the end of macro variables, '";run;quit; type nonsense.&amp;nbsp; All promoting bad coding.&amp;nbsp; Maybe I should just reply all my posts in uppercase with no punctuation or spaces or line feeds in future&amp;nbsp;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2018 15:50:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-Data-Based-on-Recent-Two-Months/m-p/490526#M128347</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-08-28T15:50:26Z</dc:date>
    </item>
    <item>
      <title>Re: Select Data Based on Recent Two Months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-Data-Based-on-Recent-Two-Months/m-p/490543#M128356</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/142314"&gt;@BCNAV&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;The reason why there is no day value is because these are aggregated monthly counts at air traffic control towers. Only monthly data is required, hence no date field is provided to me of individual flights. I can make one via:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;mdy(t1.Month,1,t1.Year) with a format of MMDDYY8.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now, when I use: intnx('month',t1.date,-2) &amp;lt; datepart(today()); Nothing is returned&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The data now looks like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Airport	Date	        Year	Month	Count
CYXX	1/1/2018	2018	1	5,091
CYXX	2/1/2018	2018	2	6,148
CYXX	3/1/2018	2018	3	11,069
CYXX	4/1/2018	2018	4	11,359
CYXX	5/1/2018	2018	5	14,552
CYXX	6/1/2018	2018	6	11,333
CYXX	7/1/2018	2018	7	7,842&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I only want the last two months ever sent out. As can been seen above, that is June and July.&lt;/P&gt;
&lt;P&gt;If I use intnx('month',t1.date,-2) &amp;lt; today();&amp;nbsp;then everything is returned.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect this is close...&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;A date value also simplifies addressing the "two previous months" when you are in February and you needed two year/month combinations. or when management comes back and says "what about 3 (or&amp;nbsp;4 or 5 or …)&amp;nbsp;months previously, or comparing first quarter of this year with first quarter of last year …&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;TODAY function returns a date value. See:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  x=today();
  put x date9.;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you use datepart(today()) you have told SAS to treat Today as datetime value and is way off:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  x=datepart(today());
  put x date9.;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Aug 2018 16:19:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-Data-Based-on-Recent-Two-Months/m-p/490543#M128356</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-08-28T16:19:01Z</dc:date>
    </item>
  </channel>
</rss>

