<?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: Selecting subset of data relative to today's date in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-subset-of-data-relative-to-today-s-date/m-p/317405#M9115</link>
    <description>&lt;P&gt;I would just use TODAY instead of datetime. I believe the time portion is throwing a monkey wrench into the equation.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data SUBSET; set ORIGINAL;
   where EVENT_REPORTED_DATETIME &amp;gt;= (%sysfunc(today())-365);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 07 Dec 2016 18:21:53 GMT</pubDate>
    <dc:creator>TheShark</dc:creator>
    <dc:date>2016-12-07T18:21:53Z</dc:date>
    <item>
      <title>Selecting subset of data relative to today's date</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-subset-of-data-relative-to-today-s-date/m-p/317401#M9114</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I have what I feel like should be a simple task, but I just can't figure it out.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am working with very large dataset stores on Oracle servers and need to use the data for a variety of Tableau dashboards. The datasets are so large that working off a live feed from the Oracle servers isn't feasible, so we have to create subsets of the data and either connect live to those, or create extracts.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I would like to do is set it up so that every time my code runs it selects the last 1 year of data, relative to the date that the code is run. Right now it is set up to pull anything over a pre-specified date, but obviously as the date gets further away the larger the dataset becomes and I don't want to have to worry about going in and changing it overy so often.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the code I tried:&lt;/P&gt;
&lt;PRE&gt;data SUBSET; set ORIGINAL;
   where EVENT_REPORTED_DATETIME &amp;gt;= (%sysfunc(DATETIME(),datetime20.) -365);
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It results in the following error:&lt;/P&gt;
&lt;PRE&gt;NOTE: Line generated by the macro function "SYSFUNC".&lt;BR /&gt;1 07DEC2016:11:10:26&lt;BR /&gt; -------&lt;BR /&gt; 22&lt;BR /&gt; 76&lt;BR /&gt;ERROR: Syntax error while parsing WHERE clause.&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, ), *, **, +, -, /, &amp;lt;, &amp;lt;=,&lt;BR /&gt; &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, ?, AND, BETWEEN, CONTAINS, EQ, GE, GT, IN, IS, LE, LIKE, LT, NE, NOT,&lt;BR /&gt; NOTIN, OR, ^, ^=, |, ||, ~, ~=.&lt;BR /&gt;&lt;BR /&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;BR /&gt;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried a few other similar methods, but they either returned no observations or all observations.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Dec 2016 18:10:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Selecting-subset-of-data-relative-to-today-s-date/m-p/317401#M9114</guid>
      <dc:creator>Jordan88</dc:creator>
      <dc:date>2016-12-07T18:10:56Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting subset of data relative to today's date</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-subset-of-data-relative-to-today-s-date/m-p/317405#M9115</link>
      <description>&lt;P&gt;I would just use TODAY instead of datetime. I believe the time portion is throwing a monkey wrench into the equation.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data SUBSET; set ORIGINAL;
   where EVENT_REPORTED_DATETIME &amp;gt;= (%sysfunc(today())-365);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Dec 2016 18:21:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Selecting-subset-of-data-relative-to-today-s-date/m-p/317405#M9115</guid>
      <dc:creator>TheShark</dc:creator>
      <dc:date>2016-12-07T18:21:53Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting subset of data relative to today's date</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-subset-of-data-relative-to-today-s-date/m-p/317417#M9117</link>
      <description>&lt;P&gt;Alright, figured it out! Your comment kind of got me going in the right direction.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is actually what I had originally tried, but it returns all entries, not just those within the last year.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I thought it might be due to the format (it is DATETIME20.) so tried DATETIME instead.&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;If enter&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;$put %sysfunc(today());&lt;/PRE&gt;
&lt;P&gt;I get the value&amp;nbsp;20795. Which is the number of days past Jan 1, 1960.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I put&lt;/P&gt;
&lt;PRE&gt;%put sysfunc(datetime())&lt;/PRE&gt;
&lt;P&gt;I get&amp;nbsp;1796730229.087 (or something similar), which is the number of SECONDS past that date. Also, when I get the minimum datetime value in my dataset, it has a value of&amp;nbsp;&lt;SPAN&gt;1785628860.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;So when I am substracting 365 from 20795 (today()), it ends up comparing my datetime (which is seconds) to a value of 20430 (which is days), so my datetime value is always larger. What I had to do was keep DATETIME() in the equation, drop the "datetime20." format (that was throwing a wrench in the works) and subtract the number of SECONDS IN A YEAR.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;SO the final equation to get it work work looks like this&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;data SUBSET; set ORIGINAL;
   where EVENT_REPORTED_DATETIME &amp;gt;= (%sysfunc(datetime())-31536000);
run;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Who knew.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Dec 2016 18:56:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Selecting-subset-of-data-relative-to-today-s-date/m-p/317417#M9117</guid>
      <dc:creator>Jordan88</dc:creator>
      <dc:date>2016-12-07T18:56:35Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting subset of data relative to today's date</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-subset-of-data-relative-to-today-s-date/m-p/317418#M9118</link>
      <description>&lt;P&gt;Your EVENT_REPORTED_DATETIME is datetime format, you could try to use datetime():&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;where &lt;SPAN&gt; EVENT_REPORTED_DATETIME&amp;gt;=&amp;nbsp;&lt;/SPAN&gt;intnx('dtmonth',datetime(),-12,'same');&lt;/P&gt;</description>
      <pubDate>Wed, 07 Dec 2016 19:08:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Selecting-subset-of-data-relative-to-today-s-date/m-p/317418#M9118</guid>
      <dc:creator>slchen</dc:creator>
      <dc:date>2016-12-07T19:08:36Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting subset of data relative to today's date</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Selecting-subset-of-data-relative-to-today-s-date/m-p/317422#M9119</link>
      <description>&lt;P&gt;Thanks! This works as well as the solution I ended up figuring out.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Dec 2016 19:22:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Selecting-subset-of-data-relative-to-today-s-date/m-p/317422#M9119</guid>
      <dc:creator>Jordan88</dc:creator>
      <dc:date>2016-12-07T19:22:22Z</dc:date>
    </item>
  </channel>
</rss>

