<?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: Datetime in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Datetime-first-day-of-year-in-macro-variable/m-p/789912#M252851</link>
    <description>Yes but, will your code change the year when a new year comes.</description>
    <pubDate>Thu, 13 Jan 2022 07:20:05 GMT</pubDate>
    <dc:creator>Pandu2</dc:creator>
    <dc:date>2022-01-13T07:20:05Z</dc:date>
    <item>
      <title>Datetime first day of year in macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datetime-first-day-of-year-in-macro-variable/m-p/789885#M252828</link>
      <description>&lt;P&gt;Hi All,&lt;BR /&gt;I hope everyone is doing good.&lt;BR /&gt;I need a datetime value for the 1st day of a year, which should look like this.&lt;BR /&gt;2022-01-01T00:00:00.000Z&lt;BR /&gt;By considering the above datetime only the year needs to be changed whenever the new year comes. The date and month should remain same i.e 01-01.&lt;BR /&gt;Example:&lt;BR /&gt;2023-01-01T00:00:00.000Z&lt;BR /&gt;The datetime value must be in a macro variable.&lt;BR /&gt;&lt;BR /&gt;Any help would be greatly appreciated.&lt;BR /&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jan 2022 09:27:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datetime-first-day-of-year-in-macro-variable/m-p/789885#M252828</guid>
      <dc:creator>Pandu2</dc:creator>
      <dc:date>2022-01-13T09:27:11Z</dc:date>
    </item>
    <item>
      <title>Re: Datetime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datetime-first-day-of-year-in-macro-variable/m-p/789888#M252830</link>
      <description>&lt;P&gt;Depending on the purpose of the macro variable it is often better not to store a formatted date, time or datetime value, but the unformatted original. The formatted value is most likely completely useless, when used to filter data. And with a normal datetime you can use intnx to shift the value one year forward.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;By considering the above datetime only the year needs to be changed whenever the new year comes&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So whenever new data arrives, which is yearly, the year should be increased. But how are you storing the date between sessions? How does the program know that it is the second time new data arrived, and the constant "2022-01-01T00:00:00.000Z" must increased by two?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe this helps, please note that i don't know the name of the datetime format displaying the datetime in the expected form.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   date = intnx('year', today(), 1, 'b');
   dt = dhms(date, 0, 0, 0);
   call symputx('next_year', put(dt, datetime.));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or, if you want to work with strings:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro demo;
   %local start next_year;
   %let start = 2022-01-01T00:00:00.000Z;
   
   %let year = %substr(&amp;amp;start, 1, 4);
   %let year = %eval(&amp;amp;year + 1);
   %let next_year = &amp;amp;year.%substr(&amp;amp;start, 5);
   %put &amp;amp;=next_year;
%mend;

%demo;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Jan 2022 06:27:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datetime-first-day-of-year-in-macro-variable/m-p/789888#M252830</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-01-13T06:27:39Z</dc:date>
    </item>
    <item>
      <title>Re: Datetime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datetime-first-day-of-year-in-macro-variable/m-p/789891#M252833</link>
      <description>Based upon the current date it should know when to change the year but not the date and month i.e 01-01.</description>
      <pubDate>Thu, 13 Jan 2022 06:41:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datetime-first-day-of-year-in-macro-variable/m-p/789891#M252833</guid>
      <dc:creator>Pandu2</dc:creator>
      <dc:date>2022-01-13T06:41:33Z</dc:date>
    </item>
    <item>
      <title>Re: Datetime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datetime-first-day-of-year-in-macro-variable/m-p/789893#M252835</link>
      <description>May I know the usage of looping here. Is it possible to achieve the required solution using current date or system date. By using current datetime the year must change whenever new year arrives and the rest should be same i.e 01-01T00:00:00.000Z</description>
      <pubDate>Thu, 13 Jan 2022 06:48:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datetime-first-day-of-year-in-macro-variable/m-p/789893#M252835</guid>
      <dc:creator>Pandu2</dc:creator>
      <dc:date>2022-01-13T06:48:22Z</dc:date>
    </item>
    <item>
      <title>Re: Datetime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datetime-first-day-of-year-in-macro-variable/m-p/789905#M252845</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/405593"&gt;@Pandu2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Based upon the current date it should know when to change the year but not the date and month i.e 01-01.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So, based on the current year, you need year+1? This is exactly what the data step i posted does. The only thing you need to do is finding an appropriate format.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jan 2022 07:08:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datetime-first-day-of-year-in-macro-variable/m-p/789905#M252845</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-01-13T07:08:56Z</dc:date>
    </item>
    <item>
      <title>Re: Datetime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datetime-first-day-of-year-in-macro-variable/m-p/789907#M252847</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let macrovar = %sysfunc(intnx(dtyear,%sysfunc(datetime()),0,b));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will give you the zero second of the current year as a raw value, which is usually better in macro variables. Formatted macro variables are only needed for display purposes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Edit: replaced the TODAY function with DATETIME&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jan 2022 08:47:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datetime-first-day-of-year-in-macro-variable/m-p/789907#M252847</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-01-13T08:47:11Z</dc:date>
    </item>
    <item>
      <title>Re: Datetime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datetime-first-day-of-year-in-macro-variable/m-p/789909#M252849</link>
      <description>It just gave me 0 value. The reason I want it to be in macro variable is I use that macro variable in a url.</description>
      <pubDate>Thu, 13 Jan 2022 07:17:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datetime-first-day-of-year-in-macro-variable/m-p/789909#M252849</guid>
      <dc:creator>Pandu2</dc:creator>
      <dc:date>2022-01-13T07:17:52Z</dc:date>
    </item>
    <item>
      <title>Re: Datetime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datetime-first-day-of-year-in-macro-variable/m-p/789910#M252850</link>
      <description>&lt;P&gt;Thought that today() returns a date, not a datetime, but maybe i am not up-to-date.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jan 2022 07:17:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datetime-first-day-of-year-in-macro-variable/m-p/789910#M252850</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-01-13T07:17:57Z</dc:date>
    </item>
    <item>
      <title>Re: Datetime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datetime-first-day-of-year-in-macro-variable/m-p/789912#M252851</link>
      <description>Yes but, will your code change the year when a new year comes.</description>
      <pubDate>Thu, 13 Jan 2022 07:20:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datetime-first-day-of-year-in-macro-variable/m-p/789912#M252851</guid>
      <dc:creator>Pandu2</dc:creator>
      <dc:date>2022-01-13T07:20:05Z</dc:date>
    </item>
    <item>
      <title>Re: Datetime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datetime-first-day-of-year-in-macro-variable/m-p/789917#M252854</link>
      <description>&lt;P&gt;Correct. Somewhere between setting up the post in my brain and typing it into the forum DATETIME changed to TODAY &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jan 2022 08:48:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datetime-first-day-of-year-in-macro-variable/m-p/789917#M252854</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-01-13T08:48:25Z</dc:date>
    </item>
    <item>
      <title>Re: Datetime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datetime-first-day-of-year-in-macro-variable/m-p/789918#M252855</link>
      <description>&lt;P&gt;See correction. Has to be DATETIME in the inner %SYSFUNC.&lt;/P&gt;
&lt;P&gt;To get the correct format, just add it as a second parameter to %SYSFUNC.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jan 2022 08:49:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datetime-first-day-of-year-in-macro-variable/m-p/789918#M252855</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-01-13T08:49:28Z</dc:date>
    </item>
    <item>
      <title>Re: Datetime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datetime-first-day-of-year-in-macro-variable/m-p/789933#M252860</link>
      <description>Thanks for the code but does your code work whenever the new year arrives?.</description>
      <pubDate>Thu, 13 Jan 2022 09:52:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datetime-first-day-of-year-in-macro-variable/m-p/789933#M252860</guid>
      <dc:creator>Pandu2</dc:creator>
      <dc:date>2022-01-13T09:52:14Z</dc:date>
    </item>
    <item>
      <title>Re: Datetime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datetime-first-day-of-year-in-macro-variable/m-p/789935#M252862</link>
      <description>&lt;P&gt;See the documentation (Maxim 1):&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/n0d1c4j8iqvqsen1r4lq8plq8atb.htm" target="_blank" rel="noopener"&gt;DATETIME Function&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jan 2022 09:56:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datetime-first-day-of-year-in-macro-variable/m-p/789935#M252862</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-01-13T09:56:49Z</dc:date>
    </item>
    <item>
      <title>Re: Datetime first day of year in macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datetime-first-day-of-year-in-macro-variable/m-p/789950#M252872</link>
      <description>%let datetime= %sysfunc(date(),year4.)-01-01T00:00:00.000Z ;&lt;BR /&gt;&lt;BR /&gt;%put &amp;amp;=datetime. ;</description>
      <pubDate>Thu, 13 Jan 2022 11:42:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datetime-first-day-of-year-in-macro-variable/m-p/789950#M252872</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-01-13T11:42:24Z</dc:date>
    </item>
  </channel>
</rss>

