<?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: SAS Query to get past 1month's date from current date in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/SAS-Query-to-get-past-1month-s-date-from-current-date/m-p/680162#M23966</link>
    <description>&lt;P&gt;Thank you for quick response!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need data date range from&amp;nbsp;&lt;SPAN&gt;30 Jul 2020 to 29 Aug 2020 inclusive.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 29 Aug 2020 01:47:13 GMT</pubDate>
    <dc:creator>jyothiN</dc:creator>
    <dc:date>2020-08-29T01:47:13Z</dc:date>
    <item>
      <title>SAS Query to get past 1month's date from current date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-Query-to-get-past-1month-s-date-from-current-date/m-p/680156#M23964</link>
      <description>&lt;P&gt;Could you please help me on the below query where i m trying to retreive data for past 1 month from current date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;query used:&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;create table test1 as Select distinct&amp;nbsp; quote_number(alphnumeric),&lt;BR /&gt;effective, TRANSACTIONDATE from Libname.table&amp;nbsp;&lt;BR /&gt;where datepart (TRANSACTIONDATE) &amp;lt; intnx('month',today(),-1)&lt;BR /&gt;and quotenumber like 'Q%'&lt;BR /&gt;order by transactiondate desc;&lt;BR /&gt;Quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;sample result set of the data retrieved:&lt;/P&gt;&lt;P&gt;QCAH3107000623 27OCT2018:00:00:00.000000 24OCT2018:21:39:25.228000&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Actually i need past 6-month's data but first trying out to get with 1 month and to apply it for 6 months&lt;/P&gt;&lt;P&gt;This gives me result of 22 million.&lt;/P&gt;&lt;P&gt;Kindly help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 29 Aug 2020 01:02:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-Query-to-get-past-1month-s-date-from-current-date/m-p/680156#M23964</guid>
      <dc:creator>jyothiN</dc:creator>
      <dc:date>2020-08-29T01:02:42Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Query to get past 1month's date from current date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-Query-to-get-past-1month-s-date-from-current-date/m-p/680161#M23965</link>
      <description>&lt;P&gt;What does "&lt;SPAN&gt;past 1 month from current date" mean? If today is 29 Aug 2020 does that mean you want 30 Jul 2020 to 29 Aug 2020 inclusive or 01 Jul 2020 to 31 Jul 2020 inclusive or some other range?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 29 Aug 2020 01:40:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-Query-to-get-past-1month-s-date-from-current-date/m-p/680161#M23965</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2020-08-29T01:40:36Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Query to get past 1month's date from current date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-Query-to-get-past-1month-s-date-from-current-date/m-p/680162#M23966</link>
      <description>&lt;P&gt;Thank you for quick response!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need data date range from&amp;nbsp;&lt;SPAN&gt;30 Jul 2020 to 29 Aug 2020 inclusive.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 29 Aug 2020 01:47:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-Query-to-get-past-1month-s-date-from-current-date/m-p/680162#M23966</guid>
      <dc:creator>jyothiN</dc:creator>
      <dc:date>2020-08-29T01:47:13Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Query to get past 1month's date from current date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-Query-to-get-past-1month-s-date-from-current-date/m-p/680170#M23967</link>
      <description>&lt;P&gt;A couple comments.&amp;nbsp; It's still August 28 here,&amp;nbsp; so over here you would want&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where datepart (TRANSACTIONDATE) &amp;gt;= "29jul2020"d&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Notice it's &amp;gt;=,&amp;nbsp; not &amp;lt;, since you apparently want the most recent month.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But why bother applying the datepart function to every observation, when you can do the equivalent test for a datetime cutoff.&amp;nbsp; I.e., the condition could be modified to:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where TRANSACTIONDATE  &amp;gt;= "29jul2020:00:00:00"dt &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So how to generate the 29jul2020:00:00:00?&amp;nbsp; You could put this in the where clause:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where TRANSACTIONDATE &amp;gt;= intnx(dtmonth,intnx('dtday',datetime(),1),-1,'same')&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The internal INTNX takes the current datetime and adds 1 day (unit DTDAY) to it, and by default aligns the result&amp;nbsp; to the beginning of the day, i.e. 29AUG2020:00:00:00.&amp;nbsp;&amp;nbsp; Then the external INTNX goes back 1 month (minus 1 DTMONTH), from that value, but is told to align it to the same day-of-month (rather than defaulting to the beginning of the month).&amp;nbsp; So it generates the datetime for 29JUL2020:00:00:00.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But wait, there's more.&amp;nbsp; Instead of telling SQL to calculate these nested functions once per observation to repeatedly generate a constant, you can use macro language to calculate the constant just once, and use the resulting macrovar in the sql, as in:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let midnight_tonight=%sysfunc(intnx(dtday,%sysfunc(datetime()),1));
%let midnight_one_month_prior=%sysfunc(putn(%sysfunc(intnx(dtmonth,&amp;amp;midnight_tonight,-1,same)),datetime20.));
%put &amp;amp;=midnight_one_month_prior;

proc sql noprint;
  create table test1 as Select distinct quote_number(alphnumeric),
  effective, TRANSACTIONDATE 
  from Libname.table 
  where TRANSACTIONDATE &amp;gt;= "&amp;amp;midnight_one_month_prior"dt
 and quotenumber like 'Q%'
  order by transactiondate desc;
Quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So this provides the correct filter, and minimizes the computing burden while doing it.&lt;/P&gt;</description>
      <pubDate>Sat, 29 Aug 2020 03:47:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-Query-to-get-past-1month-s-date-from-current-date/m-p/680170#M23967</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-08-29T03:47:45Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Query to get past 1month's date from current date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-Query-to-get-past-1month-s-date-from-current-date/m-p/680369#M23992</link>
      <description>&lt;P&gt;Hi, Greetings!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It worked and got the desired results.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just a follow-up question - in case if i want to change to get prior 6 months data - i just need to change the '-1' to '-6' in the below query you had provided?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 31 Aug 2020 06:05:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-Query-to-get-past-1month-s-date-from-current-date/m-p/680369#M23992</guid>
      <dc:creator>jyothiN</dc:creator>
      <dc:date>2020-08-31T06:05:29Z</dc:date>
    </item>
  </channel>
</rss>

