<?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 Selecting everything from the previous month based on DATETIME20. variable? in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-everything-from-the-previous-month-based-on-DATETIME20/m-p/124285#M1577</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Still being rather new to DI Studio, I'd appreciate advice on a problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In an Extract transformation, I want to extract all rows where Last_Updated (DATETIME20.) is between the first and last date of the previous month. In other words, it needs to extract everything from August based on a datetime20 variable. How do I go about doing this?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 18 Sep 2012 13:29:21 GMT</pubDate>
    <dc:creator>EinarRoed</dc:creator>
    <dc:date>2012-09-18T13:29:21Z</dc:date>
    <item>
      <title>Selecting everything from the previous month based on DATETIME20. variable?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-everything-from-the-previous-month-based-on-DATETIME20/m-p/124285#M1577</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Still being rather new to DI Studio, I'd appreciate advice on a problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In an Extract transformation, I want to extract all rows where Last_Updated (DATETIME20.) is between the first and last date of the previous month. In other words, it needs to extract everything from August based on a datetime20 variable. How do I go about doing this?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Sep 2012 13:29:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Selecting-everything-from-the-previous-month-based-on-DATETIME20/m-p/124285#M1577</guid>
      <dc:creator>EinarRoed</dc:creator>
      <dc:date>2012-09-18T13:29:21Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting everything from the previous month based on DATETIME20. variable?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-everything-from-the-previous-month-based-on-DATETIME20/m-p/124286#M1578</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There are two basic steps to take:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The DATEPART function extracts just the date portion of your datetime variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The INTNX function can retrieve the first day of the months based on a date value. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Although it's not necessary to cram everything into one statement, it can be done:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;where ( intnx('MONTH', "&amp;amp;sysdate9"d, -1) &amp;lt;= datepart(Last_Updated) &amp;lt; intnx('MONTH', "&amp;amp;sysdate9"d, 0) );&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note that &amp;amp;sysdate9 does not change, but is measured once when your session begins.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Sep 2012 14:37:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Selecting-everything-from-the-previous-month-based-on-DATETIME20/m-p/124286#M1578</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2012-09-18T14:37:14Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting everything from the previous month based on DATETIME20. variable?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-everything-from-the-previous-month-based-on-DATETIME20/m-p/124287#M1579</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As always, there is more than one right way do this...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For a month/year period extraction I kinda like to use formatted dates and perform an alpha match (which may work also for less/great than comparisons).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt;where put(date(),monyy7.) eq put(LAST_UPDATED,dtmonyy7.)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: 'Courier New';"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Now, what happens here:&lt;/P&gt;&lt;P&gt;date() returns the system date which is converted to text using the date monyy7. format = 'SEP2012'&lt;/P&gt;&lt;P&gt;LAST_UPDATE is converted to text using the dtmonyy7. date/time format = 'SEP2012'&lt;/P&gt;&lt;P&gt;And a alpha match is performed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or, you could use the datetime() function instead (and use date/time dtmonyy7 format), which returns the system date an time:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New';"&gt;where put(datetime(),dtmonyy7.) eq put(LAST_UPDATED,dtmonyy7.)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or, if you're not after an exact match, using the date yymm7. format = '2012M09'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New';"&gt;where put(date(),yymm7.) gt put(datepart(LAST_UPDATED),yymm7.)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New';"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Notice the use of the datepart function above to convert LAST_UPDATED as the used format requires strictly a date value (not date/time).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;More on SAS formats here:&lt;BR /&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a001263753.htm"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a001263753.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;More on PUT function here:&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000199354.htm" title="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000199354.htm"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000199354.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note: the use of date()/datetime() functions or &amp;amp;SYSDATE9 really depends on performance and how "accurate" you want the date to be. &amp;amp;SYSDATE9 evaluates at the beginning of the session, date()/datetime() at the moment the call is made to this functions.&lt;/P&gt;&lt;P&gt;Performance wise, the macro &amp;amp;SYSDATE9 should be "nicer" as it is evaluated once and then is part of the code as a constant value. The function is called each time the where is evaluated. Of course this could be meaningless or meaningful depending on the data's volume.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers from Portugal.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Sep 2012 15:42:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Selecting-everything-from-the-previous-month-based-on-DATETIME20/m-p/124287#M1579</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2012-09-18T15:42:54Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting everything from the previous month based on DATETIME20. variable?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-everything-from-the-previous-month-based-on-DATETIME20/m-p/124288#M1580</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just noticed you wanted the previous month, not the current one.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As demonstrated previously you just need to use the INTNX function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just replace:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;date()&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;with:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;intnx('MONTH', date(), -1)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sorry for that.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;More on the INTNX function:&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000212700.htm" title="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000212700.htm"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000212700.htm&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Sep 2012 15:48:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Selecting-everything-from-the-previous-month-based-on-DATETIME20/m-p/124288#M1580</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2012-09-18T15:48:03Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting everything from the previous month based on DATETIME20. variable?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-everything-from-the-previous-month-based-on-DATETIME20/m-p/124289#M1581</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;not tested&lt;/P&gt;&lt;P&gt;intck('dtmonth', last_updated, datetime() ) = 1 &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;or to not execute datetime() in every iteration&lt;/P&gt;&lt;P&gt;intck('dtmonth', last_updated, %sysfunc(datetime()) ) = 1&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Sep 2012 02:20:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Selecting-everything-from-the-previous-month-based-on-DATETIME20/m-p/124289#M1581</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2012-09-19T02:20:17Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting everything from the previous month based on DATETIME20. variable?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-everything-from-the-previous-month-based-on-DATETIME20/m-p/124290#M1582</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just want to underline the consequence of using function calls in a where clause.&lt;/P&gt;&lt;P&gt;As a general rule of thumb, they will prevent you from use index optimization, and will lead to a full table scan, which, of course, for large table will have a great impact on performance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I usually do, is to calculate a from and to datetime constants in a pre step (to the job or to the step), and store the as macro variable, in a datetime format. In the extract you will have:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;last_updated between "&amp;amp;FromDatetime"dt and "&amp;amp;ToDatetime"dt&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Sep 2012 08:59:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Selecting-everything-from-the-previous-month-based-on-DATETIME20/m-p/124290#M1582</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2012-09-24T08:59:48Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting everything from the previous month based on DATETIME20. variable?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-everything-from-the-previous-month-based-on-DATETIME20/m-p/124291#M1583</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;ANd to add to Linus very valuable statement: The code he used also allows the query to be pushed to the&amp;nbsp; database.&lt;/P&gt;&lt;P&gt;I normally try to avoid Precode so I often use %syfunc() instead for the same purpose as Linus outlines.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Sep 2012 09:35:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Selecting-everything-from-the-previous-month-based-on-DATETIME20/m-p/124291#M1583</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2012-09-24T09:35:44Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting everything from the previous month based on DATETIME20. variable?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-everything-from-the-previous-month-based-on-DATETIME20/m-p/124292#M1584</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Wow, I haven't considered that %sysfunc could be used for hiding "normal" function calls within regular SAS code.. Thanks for that tip!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Sep 2012 10:32:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Selecting-everything-from-the-previous-month-based-on-DATETIME20/m-p/124292#M1584</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2012-09-24T10:32:55Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting everything from the previous month based on DATETIME20. variable?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-everything-from-the-previous-month-based-on-DATETIME20/m-p/124293#M1585</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In extract transformation , where clause you can mention like this...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;StartDate &amp;lt;= &amp;amp;&lt;EM style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;last_updated&lt;/EM&gt; &amp;lt; EndDate&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and you can pass the last_updated date value in pre code(as this would be changing as per your requirement).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Shiva&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Sep 2012 09:29:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Selecting-everything-from-the-previous-month-based-on-DATETIME20/m-p/124293#M1585</guid>
      <dc:creator>shivas</dc:creator>
      <dc:date>2012-09-26T09:29:30Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting everything from the previous month based on DATETIME20. variable?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-everything-from-the-previous-month-based-on-DATETIME20/m-p/436899#M13508</link>
      <description>&lt;P&gt;Hi Astounding; I used your code in my program and it worked (i.e. when I run my data for this year, I get January and February YTD Data.&amp;nbsp; When I use your code, I get just January data).&amp;nbsp; So, it works great!&amp;nbsp; As I`m learning, I would like to understand the last part of the code.&amp;nbsp; I guess as I read it the (intnx("month", today(),-1)&amp;lt;=calendar_dt) makes sense to me (but doesn`t work on it`s own).&amp;nbsp; I`d like to better understand why it works when the last part (&amp;lt;intnx("month",today(),0)) is added to the code.&amp;nbsp; Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(intnx("month", today(),-1)&amp;lt;=calendar_dt&amp;lt;intnx("month",today(),0))&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2018 22:16:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Selecting-everything-from-the-previous-month-based-on-DATETIME20/m-p/436899#M13508</guid>
      <dc:creator>mstergia</dc:creator>
      <dc:date>2018-02-13T22:16:15Z</dc:date>
    </item>
  </channel>
</rss>

