<?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 correct the shift in date in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-correct-the-shift-in-date/m-p/955969#M45718</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data demo;
	format date weekdatx.  sat_start_of_week fri_end_of_week sat_start_of_year fri_end_of_year date9.;
	do date='28dec2013'd to '02jan2026'd;
		sat_start_of_week=intnx('week.7',date,0,'b');
		fri_end_of_week=intnx('week.7',date,0,'e');

		sat_start_of_year=mdy(1,1,year(date)) + mod(11-weekday(mdy(1,1,year(date))),7)-4;
  		fri_end_of_year=mdy(12,31,year(date))+ mod(10-weekday(mdy(1,1,year(date))),7)-4;
		output;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The sat_start_of_week and the fri_end_of_week are in line with the date value.&lt;/P&gt;
&lt;P&gt;But for the&amp;nbsp;sat_start_of_year and&amp;nbsp;fri_end_of_year, how can I make sure that 28dec2013 goes from date=28dec2013 until 02jan2015 same thing for 02jan2015&lt;/P&gt;</description>
    <pubDate>Mon, 13 Jan 2025 21:46:17 GMT</pubDate>
    <dc:creator>alepage</dc:creator>
    <dc:date>2025-01-13T21:46:17Z</dc:date>
    <item>
      <title>how to correct the shift in date</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-correct-the-shift-in-date/m-p/955969#M45718</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data demo;
	format date weekdatx.  sat_start_of_week fri_end_of_week sat_start_of_year fri_end_of_year date9.;
	do date='28dec2013'd to '02jan2026'd;
		sat_start_of_week=intnx('week.7',date,0,'b');
		fri_end_of_week=intnx('week.7',date,0,'e');

		sat_start_of_year=mdy(1,1,year(date)) + mod(11-weekday(mdy(1,1,year(date))),7)-4;
  		fri_end_of_year=mdy(12,31,year(date))+ mod(10-weekday(mdy(1,1,year(date))),7)-4;
		output;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The sat_start_of_week and the fri_end_of_week are in line with the date value.&lt;/P&gt;
&lt;P&gt;But for the&amp;nbsp;sat_start_of_year and&amp;nbsp;fri_end_of_year, how can I make sure that 28dec2013 goes from date=28dec2013 until 02jan2015 same thing for 02jan2015&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jan 2025 21:46:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-correct-the-shift-in-date/m-p/955969#M45718</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2025-01-13T21:46:17Z</dc:date>
    </item>
    <item>
      <title>Re: how to correct the shift in date</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-correct-the-shift-in-date/m-p/955976#M45719</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76331"&gt;@alepage&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;data demo;
    format date weekdatx.  sat_start_of_week fri_end_of_week sat_start_of_year fri_end_of_year date9.;
    do date='28dec2013'd to '02jan2026'd;
        sat_start_of_week=intnx('week.7',date,0,'b');
        fri_end_of_week=intnx('week.7',date,0,'e');

        sat_start_of_year=mdy(1,1,year(date)) + mod(11-weekday(mdy(1,1,year(date))),7)-4;
        fri_end_of_year=mdy(12,31,year(date))+ mod(10-weekday(mdy(&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/FONT&gt;,&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;,year(date))),7)-4;
        output;
    end;
run;&lt;/PRE&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76331"&gt;@alepage&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First of all, I think the two arguments in the last call of the MDY function which I highlighted in red should read 12 and 31, respectively (cf. &lt;A href="https://communities.sas.com/t5/SAS-Enterprise-Guide/Unable-to-find-the-begining-and-the-end-of-a-year-for-a-calendar/m-p/955803/highlight/true#M45697" target="_blank" rel="noopener"&gt;my suggestion in the other thread&lt;/A&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the other thread we started with a year (e.g., 2014) and calculated its redefined start and end dates (e.g., 28 Dec 2013 and 02 Jan 2015, resp.). Now you could use the inverse calculation to obtain that &lt;EM&gt;year&lt;/EM&gt;&amp;nbsp;(let's denote it by&amp;nbsp;&lt;FONT face="courier new,courier"&gt;y&lt;/FONT&gt;) from those &lt;EM&gt;dates&lt;/EM&gt; (and all dates between them). A similar reasoning as before leads to the following formula to achieve this:&lt;/P&gt;
&lt;PRE&gt;y=year(date+mod(13-weekday(date),7)-2)&lt;/PRE&gt;
&lt;P&gt;Using &lt;FONT face="courier new,courier"&gt;y&lt;/FONT&gt; as the third argument of the MDY function calls should produce the desired results:&lt;/P&gt;
&lt;PRE&gt;&lt;STRONG&gt;y=year(date+mod(13-weekday(date),7)-2);&lt;/STRONG&gt;
sat_start_of_year=mdy(1,1,&lt;FONT color="#00DD00"&gt;&lt;STRONG&gt;y&lt;/STRONG&gt;&lt;/FONT&gt;)+mod(11-weekday(mdy(1,1,&lt;FONT color="#00DD00"&gt;&lt;STRONG&gt;y&lt;/STRONG&gt;&lt;/FONT&gt;)),7)-4;
fri_end_of_year=mdy(12,31,&lt;STRONG&gt;&lt;FONT color="#00DD00"&gt;y&lt;/FONT&gt;&lt;/STRONG&gt;)+mod(10-weekday(mdy(&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;12&lt;/STRONG&gt;&lt;/FONT&gt;,&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;31&lt;/STRONG&gt;&lt;/FONT&gt;,&lt;FONT color="#00DD00"&gt;&lt;STRONG&gt;y&lt;/STRONG&gt;&lt;/FONT&gt;)),7)-4;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Jan 2025 23:34:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-correct-the-shift-in-date/m-p/955976#M45719</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2025-01-13T23:34:47Z</dc:date>
    </item>
    <item>
      <title>Re: how to correct the shift in date</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-correct-the-shift-in-date/m-p/955990#M45720</link>
      <description>&lt;P&gt;What exactly is the question?&lt;/P&gt;
&lt;P&gt;Are you trying to calculate from a single DATE value which Fiscal Year (for want of a better term) it falls under?&lt;/P&gt;
&lt;P&gt;It might just be easier to use the answers from your earlier questions to generate a custom format.&amp;nbsp; Or a&amp;nbsp; pair of formats, one to display the start date and one for the end date, that displays the date in style that DATE informat can read.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;sat_start_of_year=input(put(date,sat_start_of_year.),date9.);
fri_end_of_year  =input(put(date,fri_end_of_year.),date9.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As to your posted code you need add some logic to figure out which YEAR (fiscal year) the date belongs to.&lt;/P&gt;
&lt;P&gt;Try something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data demo;
  do date='25dec2013'd to '12jan2014'd;
    sat_start_of_week=intnx('week.7',date,0,'b');
    fri_end_of_week=intnx('week.7',date,0,'e');
    do fyear=year(date),year(date)-1,year(date)+1;
      sat_start_of_year=mdy(1,1,fyear) + mod(11-weekday(mdy(1,1,fyear)),7)-4;
      fri_end_of_year=mdy(1,1,fyear+1)-1 + mod(11-weekday(mdy(1,1,fyear+1)),7)-4;
      if sat_start_of_year&amp;lt;= date &amp;lt;=fri_end_of_year then leave;
    end;
    output;
  end;
  format date weekdatx. sat_: fri_: date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1736822875242.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/103694i05DC9611C5AFE6D3/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_0-1736822875242.png" alt="Tom_0-1736822875242.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2025 02:50:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-correct-the-shift-in-date/m-p/955990#M45720</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-01-14T02:50:25Z</dc:date>
    </item>
    <item>
      <title>Re: how to correct the shift in date</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-correct-the-shift-in-date/m-p/956085#M45721</link>
      <description>&lt;P&gt;Thank you very much for the sas code.&lt;/P&gt;
&lt;P&gt;Keeping the same logic, I was able to get the good value for Year, Quarter, Month and week.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I still need your help to get the proper value for:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;start_quater_date='';&lt;/P&gt;
&lt;P&gt;end_quater_date='';&lt;/P&gt;
&lt;P&gt;start_month_date="";&lt;/P&gt;
&lt;P&gt;end_mont_date='';&lt;/P&gt;
&lt;P&gt;x_dayintheyear='';&lt;/P&gt;
&lt;P&gt;x_day_inthemonth=''; and finally&lt;/P&gt;
&lt;P&gt;sat_start_previous_year='';&lt;/P&gt;
&lt;P&gt;fri_end_previous_year='';&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2025 16:49:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-correct-the-shift-in-date/m-p/956085#M45721</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2025-01-14T16:49:57Z</dc:date>
    </item>
    <item>
      <title>Re: how to correct the shift in date</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-correct-the-shift-in-date/m-p/956103#M45722</link>
      <description>&lt;P&gt;If the definitions of these dates are analogous to &lt;A href="https://communities.sas.com/t5/SAS-Enterprise-Guide/Unable-to-find-the-begining-and-the-end-of-a-year-for-a-calendar/m-p/955803/highlight/true#M45697" target="_blank" rel="noopener"&gt;those of the year start/end dates&lt;/A&gt;, the same formulas should be applicable:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The redefined "start date" of a given period (quarter, month, ...) -- always a Saturday -- is&lt;BR /&gt;
&lt;PRE&gt;d+mod(11-weekday(d),7)-4&lt;/PRE&gt;
where &lt;FONT face="courier new,courier"&gt;d&lt;/FONT&gt; is the commonly used start date of the period (e.g., July 1 for the third quarter). Compared to the original date (&lt;FONT face="courier new,courier"&gt;d&lt;/FONT&gt;), the new date is shifted by −4, −3, −2, −1, 0, +1 or +2 days, depending on the weekday of &lt;FONT face="courier new,courier"&gt;d&lt;/FONT&gt;.&lt;/LI&gt;
&lt;LI&gt;The redefined "end date" of a given period (quarter, month, ...) -- always a Friday -- is&lt;BR /&gt;
&lt;PRE&gt;e+mod(10-weekday(e),7)-4&lt;/PRE&gt;
where &lt;FONT face="courier new,courier"&gt;e&lt;/FONT&gt; is the commonly used end date of the period (e.g., September 30 for the third quarter). Compared to the original date (&lt;FONT face="courier new,courier"&gt;e&lt;/FONT&gt;), the new date is shifted by −4, −3, −2, −1, 0, +1 or +2 days, depending on the weekday of &lt;FONT face="courier new,courier"&gt;e&lt;/FONT&gt;.&lt;/LI&gt;
&lt;LI&gt;Given an arbitrary date, the redefined period containing that date can be determined as the commonly used period of the shifted date&lt;BR /&gt;
&lt;PRE&gt;date+mod(13-weekday(date),7)-2&lt;/PRE&gt;
Example: For &lt;FONT face="courier new,courier"&gt;date='01OCT2015'd&lt;/FONT&gt; the expression above yields &lt;FONT face="courier new,courier"&gt;'30SEP2015'd&lt;/FONT&gt;, which is commonly regarded as a day in the third quarter of 2015. Hence, 1 Oct 2015 falls into the redefined "third quarter of 2015" -- and this is consistent with the start and end dates of that period as calculated using the two formulas under 1. and 2., i.e., 27 Jun 2015 and 02 Oct 2015, respectively.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Tue, 14 Jan 2025 18:59:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-correct-the-shift-in-date/m-p/956103#M45722</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2025-01-14T18:59:27Z</dc:date>
    </item>
    <item>
      <title>Re: how to correct the shift in date</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-correct-the-shift-in-date/m-p/956129#M45723</link>
      <description>&lt;P&gt;I was able to estimate the good month_start_date and the good month_end_date&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do we estimate the x day of the year. Starting from 1 on 18dec2023 and ending with 371 on 02jan2015&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2025 20:26:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-correct-the-shift-in-date/m-p/956129#M45723</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2025-01-14T20:26:34Z</dc:date>
    </item>
    <item>
      <title>Re: how to correct the shift in date</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-correct-the-shift-in-date/m-p/956158#M45724</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76331"&gt;@alepage&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;How do we estimate the x day of the year. Starting from 1 on 18dec2023 and ending with 371 on 02jan2015&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Can you please share your definition of "the x day of the year"? I could only guess that you mean the x&lt;EM&gt;th&lt;/EM&gt; day of the (redefined) year or some &lt;EM&gt;x&lt;/EM&gt;-days period (with, say, &lt;EM&gt;x&lt;/EM&gt;=80 or &lt;EM&gt;x&lt;/EM&gt;=100).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"371 on 02jan2015" matches the 371 days and the end date of the redefined year "2014" -- but its start date ("day 1") is &lt;FONT face="courier new,courier"&gt;'02JAN2015'd-370='&lt;STRONG&gt;2&lt;/STRONG&gt;8DEC20&lt;STRONG&gt;1&lt;/STRONG&gt;3'd&lt;/FONT&gt;, not &lt;FONT face="courier new,courier"&gt;'18DEC2023'd&lt;/FONT&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jan 2025 08:12:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-correct-the-shift-in-date/m-p/956158#M45724</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2025-01-15T08:12:23Z</dc:date>
    </item>
    <item>
      <title>Re: how to correct the shift in date</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-correct-the-shift-in-date/m-p/956195#M45725</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have been using the intck function and it works very well.&lt;/P&gt;
&lt;P&gt;x day of the year=intck('day',PRV_Dt_Annee_Deb,date) + 1 ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jan 2025 14:47:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-correct-the-shift-in-date/m-p/956195#M45725</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2025-01-15T14:47:43Z</dc:date>
    </item>
  </channel>
</rss>

