<?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 how to get 5 days back datetime from current day in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-5-days-back-datetime-from-current-day/m-p/908928#M358599</link>
    <description>Data _null_;&lt;BR /&gt;Call symput (‘currdt’,put(datetime(),datetime20.));&lt;BR /&gt;Call symput(“prvdt’,put(datetime()-5,datetime20.));&lt;BR /&gt;Run;&lt;BR /&gt;%put &amp;amp;currdt.;&lt;BR /&gt;%put &amp;amp;prvdt.;&lt;BR /&gt;&lt;BR /&gt;Prvdt is not returning expected result, please advise.&lt;BR /&gt;Thank you</description>
    <pubDate>Tue, 19 Dec 2023 21:00:53 GMT</pubDate>
    <dc:creator>cm3</dc:creator>
    <dc:date>2023-12-19T21:00:53Z</dc:date>
    <item>
      <title>how to get 5 days back datetime from current day</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-5-days-back-datetime-from-current-day/m-p/908928#M358599</link>
      <description>Data _null_;&lt;BR /&gt;Call symput (‘currdt’,put(datetime(),datetime20.));&lt;BR /&gt;Call symput(“prvdt’,put(datetime()-5,datetime20.));&lt;BR /&gt;Run;&lt;BR /&gt;%put &amp;amp;currdt.;&lt;BR /&gt;%put &amp;amp;prvdt.;&lt;BR /&gt;&lt;BR /&gt;Prvdt is not returning expected result, please advise.&lt;BR /&gt;Thank you</description>
      <pubDate>Tue, 19 Dec 2023 21:00:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-5-days-back-datetime-from-current-day/m-p/908928#M358599</guid>
      <dc:creator>cm3</dc:creator>
      <dc:date>2023-12-19T21:00:53Z</dc:date>
    </item>
    <item>
      <title>Re: how to get 5 days back datetime from current day</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-5-days-back-datetime-from-current-day/m-p/908933#M358601</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/93207"&gt;@cm3&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data _null_;
	currdt = datetime();
	Call symput ('currdt',put(currdt,datetime20.));
	prvdt = intnx('dtday',currdt,-5,'same');
	Call symput('prvdt',put(prvdt,datetime20.));
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Dec 2023 21:28:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-5-days-back-datetime-from-current-day/m-p/908933#M358601</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2023-12-19T21:28:41Z</dc:date>
    </item>
    <item>
      <title>Re: how to get 5 days back datetime from current day</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-5-days-back-datetime-from-current-day/m-p/908935#M358602</link>
      <description>&lt;P&gt;You go back 5 seconds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's correct code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
a=datetime();
b=INTNX('DTDAY',a,-5,'SAME');
*format a b datetime20.;
Call symputx('currdt',put(a,datetime20.));
Call symputx('prvdt' ,put(b,datetime20.));
Run;
%put &amp;amp;=currdt.;
%put &amp;amp;=prvdt.;
/* end of program*/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2023 21:32:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-5-days-back-datetime-from-current-day/m-p/908935#M358602</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2023-12-19T21:32:03Z</dc:date>
    </item>
    <item>
      <title>Re: how to get 5 days back datetime from current day</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-5-days-back-datetime-from-current-day/m-p/908937#M358603</link>
      <description>&lt;P&gt;The function you want would be INTNX. Subtracting 5 just gets you 5 seconds earlier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to shift a datetime value by days what should happen with the Time portion of the value? Your choices would be the Beginning of the day, the Same time of day or the End of the day&lt;/P&gt;
&lt;P&gt;The INTNX function first parameter is an interval. When you want to shift a datetime value by day (or week, month, year ) use DT before the interval to let SAS know that the expected input value is a Datetime&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Data _null_;
Call symputx ('currdt',put(datetime(),datetime20.));
Call symputx ('prvdtB',put(intnx('dtday',datetime(),-5,'B'),datetime20.));
Call symputx ('prvdtS',put(intnx('dtday',datetime(),-5,'S'),datetime20.));
Call symputx ('prvdtE',put(intnx('dtday',datetime(),-5,'E'),datetime20.));
Run;

%put &amp;amp;prvdtB. &amp;amp;prvdtS. &amp;amp;prvdtE. ;&lt;/PRE&gt;
&lt;P&gt;Note that the code you posted does not run because somewhere along the line it picked up "smart quotes", the curly looking ones. They are not usable in SAS code. Plus a mismatch of double and single. It is best to post code into a text box opened on the forum with the &amp;lt;/&amp;gt; as the forum software will reformat some text pasted into the main windows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note use of SYMPUTX function instead of Symput. Symputx will remove leading and trailing spaces that otherwise frequently appear in conversions like this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/93207"&gt;@cm3&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Data _null_;&lt;BR /&gt;Call symput (&lt;FONT size="6"&gt;&lt;STRONG&gt;&lt;FONT color="#800080"&gt;‘&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;currdt&lt;FONT size="6" color="#800080"&gt;&lt;STRONG&gt;’&lt;/STRONG&gt;&lt;/FONT&gt;,put(datetime(),datetime20.));&lt;BR /&gt;Call symput(&lt;FONT size="6" color="#800080"&gt;&lt;STRONG&gt;“&lt;/STRONG&gt;&lt;/FONT&gt;prvdt&lt;FONT size="6" color="#800080"&gt;&lt;STRONG&gt;’&lt;/STRONG&gt;&lt;/FONT&gt;,put(datetime()-5,datetime20.));&lt;BR /&gt;Run;&lt;BR /&gt;%put &amp;amp;currdt.;&lt;BR /&gt;%put &amp;amp;prvdt.;&lt;BR /&gt;&lt;BR /&gt;Prvdt is not returning expected result, please advise.&lt;BR /&gt;Thank you&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2023 21:35:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-5-days-back-datetime-from-current-day/m-p/908937#M358603</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-12-19T21:35:26Z</dc:date>
    </item>
    <item>
      <title>Re: how to get 5 days back datetime from current day</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-5-days-back-datetime-from-current-day/m-p/908938#M358604</link>
      <description>It worked. Thank you Sir.</description>
      <pubDate>Tue, 19 Dec 2023 21:36:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-5-days-back-datetime-from-current-day/m-p/908938#M358604</guid>
      <dc:creator>cm3</dc:creator>
      <dc:date>2023-12-19T21:36:22Z</dc:date>
    </item>
  </channel>
</rss>

