<?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: To reduce days from a date in proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/To-reduce-days-from-a-date-in-proc-sql/m-p/478963#M123572</link>
    <description>I am passing the date as a macro variable. Just like sysdate&lt;BR /&gt;</description>
    <pubDate>Wed, 18 Jul 2018 09:09:42 GMT</pubDate>
    <dc:creator>NK29</dc:creator>
    <dc:date>2018-07-18T09:09:42Z</dc:date>
    <item>
      <title>To reduce  days from a date in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-reduce-days-from-a-date-in-proc-sql/m-p/478954#M123568</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have been using this to get data between system date and 5 days through sql statement&lt;/P&gt;&lt;P&gt;select *&lt;/P&gt;&lt;P&gt;from Table&lt;/P&gt;&lt;P&gt;where date BETWEEN SYSDATE -&amp;amp;days AND SYSDATE&lt;/P&gt;&lt;P&gt;days is initialized to 5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now,&lt;/P&gt;&lt;P&gt;Instead of SYSDATE, i need to use my own date already preset in dataset called FL_DT . I am passing FL_DT as a macro variable&lt;/P&gt;&lt;P&gt;select *&lt;/P&gt;&lt;P&gt;from Table&lt;/P&gt;&lt;P&gt;where date BETWEEN &amp;amp;FL_DT -&amp;amp;days AND &amp;amp;FL_DT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It is in Date9 format and i need to reduce 5 days from it in the same sql format as above. Could it be possible?&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 08:55:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-reduce-days-from-a-date-in-proc-sql/m-p/478954#M123568</guid>
      <dc:creator>NK29</dc:creator>
      <dc:date>2018-07-18T08:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: To reduce  days from a date in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-reduce-days-from-a-date-in-proc-sql/m-p/478957#M123571</link>
      <description>&lt;P&gt;SAS dates (numeric variable with one of the date formats attached) are counts of days, so you can use simple subtractions.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 08:45:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-reduce-days-from-a-date-in-proc-sql/m-p/478957#M123571</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-07-18T08:45:17Z</dc:date>
    </item>
    <item>
      <title>Re: To reduce days from a date in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-reduce-days-from-a-date-in-proc-sql/m-p/478963#M123572</link>
      <description>I am passing the date as a macro variable. Just like sysdate&lt;BR /&gt;</description>
      <pubDate>Wed, 18 Jul 2018 09:09:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-reduce-days-from-a-date-in-proc-sql/m-p/478963#M123572</guid>
      <dc:creator>NK29</dc:creator>
      <dc:date>2018-07-18T09:09:42Z</dc:date>
    </item>
    <item>
      <title>Re: To reduce days from a date in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-reduce-days-from-a-date-in-proc-sql/m-p/478966#M123573</link>
      <description>&lt;P&gt;Since you want to use your date-stored-in-a-macro-variable for comparisons, I strongly advise to store the raw numerical value (eg 21383 for 2018-07-18) in the macro variable, so you don't have to use "&amp;amp;mydate."d all the time. As said, it's a simple subtraction.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 09:19:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-reduce-days-from-a-date-in-proc-sql/m-p/478966#M123573</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-07-18T09:19:30Z</dc:date>
    </item>
    <item>
      <title>Re: To reduce  days from a date in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-reduce-days-from-a-date-in-proc-sql/m-p/478973#M123579</link>
      <description>&lt;P&gt;You just need to use the date constant format, e.g.:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select *
from Table
where date BETWEEN "&amp;amp;FL_DT"d -&amp;amp;days AND "&amp;amp;FL_DT"d&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I much prefer that to the solution suggested by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;, which would make the code much harder to read.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The alternative is to assign the date constant format to the variable (or another variable, if you prefer that) first:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let FL_DT="&amp;amp;FT_DT"d;
select *
from Table
where date BETWEEN &amp;amp;FL_DT -&amp;amp;days AND &amp;amp;FL_DT&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Jul 2018 10:07:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-reduce-days-from-a-date-in-proc-sql/m-p/478973#M123579</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-07-18T10:07:58Z</dc:date>
    </item>
    <item>
      <title>Re: To reduce  days from a date in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-reduce-days-from-a-date-in-proc-sql/m-p/478988#M123588</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I much prefer that to the solution suggested by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;, which would make the code much harder to read.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I beg to differ. I don't see where&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select *
from have
where date between &amp;amp;FL_DT -&amp;amp;days and &amp;amp;FL_DT;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is much harder to read than&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 "&amp;amp;FL_DT"d -&amp;amp;days and "&amp;amp;FL_DT"d;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since the date9 format is not used by any software outside of SAS (that I know of), there will always be a step in your SAS code that converts an incoming date to something usable in SAS. Whether you use date9. or best. there when creating the macro variable makes no difference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The ONLY real difference that happens is the display of values in the log when you use the macro variable in a &lt;EM&gt;where&lt;/EM&gt; condition in a &lt;EM&gt;data&lt;/EM&gt; step. That won't make much of a difference when debugging, as the human-readable form of the date can be made visible in the "import" step mentioned above.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 11:22:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-reduce-days-from-a-date-in-proc-sql/m-p/478988#M123588</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-07-18T11:22:19Z</dc:date>
    </item>
    <item>
      <title>Re: To reduce  days from a date in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-reduce-days-from-a-date-in-proc-sql/m-p/479411#M123743</link>
      <description>&lt;P&gt;What you suggested was this: "&lt;SPAN&gt;I strongly advise to store the raw numerical value (eg 21383 for 2018-07-18) in the macro variable, so you don't have to use "&amp;amp;mydate."d all the time." &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;That is what I thought was a bad idea, as you cannot easily see what a number means. 21384 is not as easy to understand when debugging as "19JUL2018"d.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jul 2018 08:15:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-reduce-days-from-a-date-in-proc-sql/m-p/479411#M123743</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-07-19T08:15:15Z</dc:date>
    </item>
    <item>
      <title>Re: To reduce days from a date in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-reduce-days-from-a-date-in-proc-sql/m-p/479413#M123744</link>
      <description>Hi when I'm reading date into a macro variable from my dataset, it is in&lt;BR /&gt;format 02JUN2018:00:00:00. P. S I am using proc sql to read it into a macro&lt;BR /&gt;variable seperated by comma&lt;BR /&gt;</description>
      <pubDate>Thu, 19 Jul 2018 08:23:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-reduce-days-from-a-date-in-proc-sql/m-p/479413#M123744</guid>
      <dc:creator>NK29</dc:creator>
      <dc:date>2018-07-19T08:23:42Z</dc:date>
    </item>
    <item>
      <title>Re: To reduce days from a date in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-reduce-days-from-a-date-in-proc-sql/m-p/479419#M123749</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/221654"&gt;@NK29&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hi when I'm reading date into a macro variable from my dataset, it is in&lt;BR /&gt;format 02JUN2018:00:00:00. P. S I am using proc sql to read it into a macro&lt;BR /&gt;variable seperated by comma&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So you do not have dates, but datetimes. Use the datepart() function to extract the date.&lt;/P&gt;
&lt;P&gt;And in your initial post, you&amp;nbsp;CAN NOT use a macro variable that contains a list of dates.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jul 2018 08:47:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-reduce-days-from-a-date-in-proc-sql/m-p/479419#M123749</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-07-19T08:47:38Z</dc:date>
    </item>
  </channel>
</rss>

