<?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: week calculation for indian financial calender in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/week-calculation-for-indian-financial-calender/m-p/563982#M158159</link>
    <description>&lt;P&gt;You need to make the calculation conditional:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input date :date9.;
format date yymmddd10.;
datalines;
01APR2019
13MAY2019
06JAN2020
;

data want;
set have;
if date &amp;gt;= mdy(4,1,year(date))
then week_id = week(date) - 12;
else week_id = week(date) + 41;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The result matches your example:&lt;/P&gt;
&lt;PRE&gt;      date    week_id

2019-04-01        1  
2019-05-13        7  
2020-01-06       42  
&lt;/PRE&gt;
&lt;P&gt;But I'm not completely sure it works for all years, the values of 12 and 53 may need to be adapted depending on the weekday of January 1 or April 1.&lt;/P&gt;</description>
    <pubDate>Thu, 06 Jun 2019 07:18:55 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-06-06T07:18:55Z</dc:date>
    <item>
      <title>week calculation for indian financial calender</title>
      <link>https://communities.sas.com/t5/SAS-Programming/week-calculation-for-indian-financial-calender/m-p/563977#M158156</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to derive a week_id variable based on dates. As SAS starts calculating week from 01JAN but i want that should start with 01APR.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looking for following result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Week_id&lt;/P&gt;
&lt;P&gt;01APR2019&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;13MAY2019&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7&lt;/P&gt;
&lt;P&gt;06JAN2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;42&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;following code is working fine till 31DEC2019 but for jan it is not working. Kindly help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA A;&lt;/P&gt;
&lt;P&gt;Week_id=week(date)-12;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jun 2019 06:52:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/week-calculation-for-indian-financial-calender/m-p/563977#M158156</guid>
      <dc:creator>umashankersaini</dc:creator>
      <dc:date>2019-06-06T06:52:03Z</dc:date>
    </item>
    <item>
      <title>Re: week calculation for indian financial calender</title>
      <link>https://communities.sas.com/t5/SAS-Programming/week-calculation-for-indian-financial-calender/m-p/563982#M158159</link>
      <description>&lt;P&gt;You need to make the calculation conditional:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input date :date9.;
format date yymmddd10.;
datalines;
01APR2019
13MAY2019
06JAN2020
;

data want;
set have;
if date &amp;gt;= mdy(4,1,year(date))
then week_id = week(date) - 12;
else week_id = week(date) + 41;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The result matches your example:&lt;/P&gt;
&lt;PRE&gt;      date    week_id

2019-04-01        1  
2019-05-13        7  
2020-01-06       42  
&lt;/PRE&gt;
&lt;P&gt;But I'm not completely sure it works for all years, the values of 12 and 53 may need to be adapted depending on the weekday of January 1 or April 1.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jun 2019 07:18:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/week-calculation-for-indian-financial-calender/m-p/563982#M158159</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-06-06T07:18:55Z</dc:date>
    </item>
    <item>
      <title>Re: week calculation for indian financial calender</title>
      <link>https://communities.sas.com/t5/SAS-Programming/week-calculation-for-indian-financial-calender/m-p/563983#M158160</link>
      <description>&lt;P&gt;In data warehousing this is usually handled by a date dimension.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In SAS, you can do something similar with a format (or even a date dimension if you want to join on date).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All days from 01JAN1960 to 31DEC2099 are only 51K rows...not *that* big for a format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps you can run with this code and modify it to suit your requirements.&amp;nbsp; For example, I don't know the day your week starts (eg. Sun or Mon):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cntlin;
   length fmtname $32 start end label 8;
   length weekday 8;  * ignored by proc format but useful for debugging ;
   fmtname="financialweek";
   retain label 0;
   do start="01APR1960"d to "31DEC2099"d;
      end=start;
      if month(start)=4 and day(start)=1 then label=1;
      weekday=weekday(start);  * not needed for debugging ;
      if weekday=1 then label+1;
      output;
   end;
   format start end date9.;
run;

proc format cntlin=cntlin;
run;

data test;
   set cntlin;&lt;BR /&gt;   financialweek=input(put(start,financialweek.-L),8.);
run;
   &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also:&lt;/P&gt;
&lt;P&gt;Formats can accept character or numeric arguments, and always return character results.&lt;/P&gt;
&lt;P&gt;Informats always accept character arguments, and can return character or numeric results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since dates are numeric, and your desired week number is numeric, you'll need to convert either way.&amp;nbsp; I chose to create a numeric format, and use the input function to convert the format output to numeric.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jun 2019 07:23:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/week-calculation-for-indian-financial-calender/m-p/563983#M158160</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-06-06T07:23:17Z</dc:date>
    </item>
    <item>
      <title>Re: week calculation for indian financial calender</title>
      <link>https://communities.sas.com/t5/SAS-Programming/week-calculation-for-indian-financial-calender/m-p/564009#M158170</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/46512"&gt;@umashankersaini&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does week 1 of a year always start on the first Sunday in April? Is that the logic you need?&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jun 2019 09:42:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/week-calculation-for-indian-financial-calender/m-p/564009#M158170</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-06-06T09:42:25Z</dc:date>
    </item>
    <item>
      <title>Re: week calculation for indian financial calender</title>
      <link>https://communities.sas.com/t5/SAS-Programming/week-calculation-for-indian-financial-calender/m-p/564081#M158193</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Week_id=week(date-('01apr1960'd - '01jan1960'd));&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jun 2019 13:23:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/week-calculation-for-indian-financial-calender/m-p/564081#M158193</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-06-06T13:23:10Z</dc:date>
    </item>
    <item>
      <title>Re: week calculation for indian financial calender</title>
      <link>https://communities.sas.com/t5/SAS-Programming/week-calculation-for-indian-financial-calender/m-p/564167#M158221</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/46512"&gt;@umashankersaini&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi Team,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to derive a week_id variable based on dates. As SAS starts calculating week from 01JAN but i want that should start with 01APR.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looking for following result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Week_id&lt;/P&gt;
&lt;P&gt;01APR2019&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;13MAY2019&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7&lt;/P&gt;
&lt;P&gt;06JAN2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;42&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;following code is working fine till 31DEC2019 but for jan it is not working. Kindly help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA A;&lt;/P&gt;
&lt;P&gt;Week_id=week(date)-12;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You say that this works for 31DEC2019&lt;/P&gt;
&lt;PRE&gt;DATA A;
Week_id=week(date)-12;
run;
&lt;/PRE&gt;
&lt;P&gt;Since that returns 40, how does&amp;nbsp; 06JAN2020&amp;nbsp;&amp;nbsp;become week&amp;nbsp;42 when it is only 7 days later? I really think that you mean week 41.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an approach using the INTCK function. There a couple of different ways to treat start of week boundaries with the INTCK function, using the 'D' discrete or 'C' continuous method option.&lt;/P&gt;
&lt;PRE&gt;data example;
   do date='01APR2019'd to '31MAR2021'd ;
      week = intck('week',mdy(4,1, year(date) - (month(date)&amp;lt;4) ),date,'D')+1;
      week2 = intck('week',mdy(4,1, year(date) - (month(date)&amp;lt;4) ),date,'C')+1;
      output;
   end;
   format date  date9.;
run;
&lt;/PRE&gt;
&lt;P&gt;BEAWARE: From the documentation&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;dates are not in the same discrete interval.)&lt;/P&gt;
&lt;DIV class="xis-paragraph" id="n1gr1p7iw5ldafn1wcs8mlebipln"&gt;Using the discrete method, WEEK intervals are determined by the number of Sundays, the default first day of the week, that occur between the &lt;SPAN class="xis-userSuppliedValue"&gt;start-date&lt;/SPAN&gt; and the &lt;SPAN class="xis-userSuppliedValue"&gt;end-date&lt;/SPAN&gt;, and not by how many seven-day periods fall between those dates. To count the number of seven-day periods between &lt;SPAN class="xis-userSuppliedValue"&gt;start-date&lt;/SPAN&gt; and &lt;SPAN class="xis-userSuppliedValue"&gt;end-date&lt;/SPAN&gt;, use the continuous method.&lt;/DIV&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So since your "fiscal year" is likely to start on a day other than SUNDAY&amp;nbsp; you may have to consider what the definition of your actual start day of the first week might be.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For a number of purposes as "week" is&amp;nbsp;a poor measure due to the dependency of start of the week, relationship to start of a year and the fact that years do not actually divide evenly into weeks 365/7 = 52.14 "weeks" or 366/7 = 52.28 "weeks"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jun 2019 15:24:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/week-calculation-for-indian-financial-calender/m-p/564167#M158221</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-06-06T15:24:18Z</dc:date>
    </item>
    <item>
      <title>Re: week calculation for indian financial calender</title>
      <link>https://communities.sas.com/t5/SAS-Programming/week-calculation-for-indian-financial-calender/m-p/568897#M160242</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am able to derive the desired output by following code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data _null_;&lt;BR /&gt;SD = intnx('week',today(),-1,'b')+1;&lt;BR /&gt;WK_ID=intck('week',intnx('month12.4',SD,0),SD)+1;&lt;BR /&gt;call symput('WK_ID',WK_ID);&lt;BR /&gt;Run;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jun 2019 18:31:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/week-calculation-for-indian-financial-calender/m-p/568897#M160242</guid>
      <dc:creator>umashankersaini</dc:creator>
      <dc:date>2019-06-25T18:31:56Z</dc:date>
    </item>
  </channel>
</rss>

