<?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: How to change year of datetime ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-year-of-datetime/m-p/482623#M125040</link>
    <description>&lt;P&gt;Check out the function INTNX.&lt;/P&gt;&lt;P&gt;From this useful &lt;A href="http://support.sas.com/documentation/cdl/en/etsug/63939/HTML/default/viewer.htm#etsug_intervals_sect014.htm" target="_self"&gt;page&lt;/A&gt;:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;STRONG&gt;INTNX( '&lt;I&gt;datetime-interval&lt;/I&gt;',&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;I&gt;datetime&lt;/I&gt;,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;I&gt;n &amp;lt;, 'alignment'&amp;gt;&lt;/I&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;returns the date or datetime value of the beginning of the interval that is&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;n&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;intervals from the interval that contains the given date or datetime value. The optional&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;alignment&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;argument specifies that the returned date is aligned to the beginning, middle, or end of the interval. Beginning is the default. In addition, you can specify SAME (S) alignment. The SAME alignment bases the alignment of the calculated date or datetime value on the alignment of the input date or datetime value. As illustrated in the following example, the SAME alignment can be used to calculate the meaning of "same day next year" or "same day two weeks from now."&lt;/P&gt;&lt;PRE&gt;   nextYear = INTNX( 'YEAR', '15Apr2007'D, 1, 'S' );
   TwoWeeks = INTNX( 'WEEK', '15Apr2007'D, 2, 'S' );&lt;/PRE&gt;&lt;P&gt;The preceding example returns '15Apr2008'D for&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="variable"&gt;nextYear&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;and '29Apr2007'D for&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="variable"&gt;TwoWeeks&lt;/SPAN&gt;.&lt;/P&gt;&lt;P&gt;For all values of alignment, the number of discrete intervals&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;n&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;between the input date and the resulting date agrees with the input value. In the following example, the result is always that&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="variable"&gt;n2&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;=&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="variable"&gt;n1&lt;/SPAN&gt;:&lt;/P&gt;&lt;PRE&gt;   date2 = INTNX( interval, date1, n1, align );
   n2 = INTCK( interval, date1, date2 );&lt;/PRE&gt;&lt;P&gt;The preceding example uses the DISCRETE method of the INTCK function by default. The result&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="variable"&gt;n2&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;=&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="variable"&gt;n1&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;does not always apply when the CONTINUOUS method of the INTCK function is specified.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;</description>
    <pubDate>Mon, 30 Jul 2018 21:50:37 GMT</pubDate>
    <dc:creator>Urban_Science</dc:creator>
    <dc:date>2018-07-30T21:50:37Z</dc:date>
    <item>
      <title>How to change year of datetime ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-year-of-datetime/m-p/482616#M125035</link>
      <description>&lt;P&gt;All,&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;I am looking for help on changing the year of datetime column in a SAS dataset.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/22119iB5FCDD185BAA2C8C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;BR /&gt;I have provided a screenshot of the column. I would like to learn 2 things :&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. How can I change the year of the datetime column shown above ?&amp;nbsp;&lt;BR /&gt;2. How can I generate timestamps for nth year from the given column ? (I am trying to do it for 6th and 11th years)&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Do i = 1 %To 2; &lt;BR /&gt;%Let YearInterval = %Eval(&amp;amp;i.*5 + 1); &lt;BR /&gt;Proc SQL INOBS = 8760; 
	Create Table Work.Want As 
	Select 
	DHMS(MDY(MONTH(DATEPART(Timestamp__yyyy_MM_dd_HH_mm_ss_)),&lt;BR /&gt;              DAY(DATEPART(Timestamp__yyyy_MM_dd_HH_mm_ss_)),&lt;BR /&gt;              YEAR(DATEPART(Timestamp__yyyy_MM_dd_HH_mm_ss_))+ &amp;amp;YearInterval),0,0,timepart(Timestamp__yyyy_MM_dd_HH_mm_ss_)) &lt;BR /&gt;        as Timestamp__yyyy_MM_dd_HH_mm_ss_
	From Work.Have; 
Quit; &lt;BR /&gt;%End; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jul 2018 21:22:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-year-of-datetime/m-p/482616#M125035</guid>
      <dc:creator>UdayGuntupalli</dc:creator>
      <dc:date>2018-07-30T21:22:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to change year of datetime ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-year-of-datetime/m-p/482623#M125040</link>
      <description>&lt;P&gt;Check out the function INTNX.&lt;/P&gt;&lt;P&gt;From this useful &lt;A href="http://support.sas.com/documentation/cdl/en/etsug/63939/HTML/default/viewer.htm#etsug_intervals_sect014.htm" target="_self"&gt;page&lt;/A&gt;:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;STRONG&gt;INTNX( '&lt;I&gt;datetime-interval&lt;/I&gt;',&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;I&gt;datetime&lt;/I&gt;,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;I&gt;n &amp;lt;, 'alignment'&amp;gt;&lt;/I&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;returns the date or datetime value of the beginning of the interval that is&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;n&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;intervals from the interval that contains the given date or datetime value. The optional&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;alignment&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;argument specifies that the returned date is aligned to the beginning, middle, or end of the interval. Beginning is the default. In addition, you can specify SAME (S) alignment. The SAME alignment bases the alignment of the calculated date or datetime value on the alignment of the input date or datetime value. As illustrated in the following example, the SAME alignment can be used to calculate the meaning of "same day next year" or "same day two weeks from now."&lt;/P&gt;&lt;PRE&gt;   nextYear = INTNX( 'YEAR', '15Apr2007'D, 1, 'S' );
   TwoWeeks = INTNX( 'WEEK', '15Apr2007'D, 2, 'S' );&lt;/PRE&gt;&lt;P&gt;The preceding example returns '15Apr2008'D for&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="variable"&gt;nextYear&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;and '29Apr2007'D for&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="variable"&gt;TwoWeeks&lt;/SPAN&gt;.&lt;/P&gt;&lt;P&gt;For all values of alignment, the number of discrete intervals&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;n&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;between the input date and the resulting date agrees with the input value. In the following example, the result is always that&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="variable"&gt;n2&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;=&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="variable"&gt;n1&lt;/SPAN&gt;:&lt;/P&gt;&lt;PRE&gt;   date2 = INTNX( interval, date1, n1, align );
   n2 = INTCK( interval, date1, date2 );&lt;/PRE&gt;&lt;P&gt;The preceding example uses the DISCRETE method of the INTCK function by default. The result&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="variable"&gt;n2&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;=&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="variable"&gt;n1&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;does not always apply when the CONTINUOUS method of the INTCK function is specified.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Mon, 30 Jul 2018 21:50:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-year-of-datetime/m-p/482623#M125040</guid>
      <dc:creator>Urban_Science</dc:creator>
      <dc:date>2018-07-30T21:50:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to change year of datetime ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-year-of-datetime/m-p/482666#M125063</link>
      <description>Because it’s date time variable, your interval should be DTYEAR.</description>
      <pubDate>Tue, 31 Jul 2018 01:09:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-year-of-datetime/m-p/482666#M125063</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-07-31T01:09:59Z</dc:date>
    </item>
  </channel>
</rss>

