<?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 assign Jan 1 to Jan 7 in a year as week 1? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-Jan-1-to-Jan-7-in-a-year-as-week-1/m-p/634958#M188487</link>
    <description>&lt;P&gt;Does that mean the last week of the year can have less than 7 days? If so then below should work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  format dt date9.;
  input dt:date9.;
  week_in_year=ceil((dt-intnx('year',dt,0,'b')+1)/7);
  datalines;
29dec2019
30dec2019
31dec2019
01jan2020
02jan2020
07jan2020
08jan2020
29dec2020
30dec2020
31dec2020
01jan2021
;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV id="tinyMceEditorPatrick_1" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1585204170027.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/37384i993AC549C7C0F5BF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1585204170027.png" alt="Patrick_0-1585204170027.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV id="tinyMceEditorPatrick_4" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV id="tinyMceEditorPatrick_3" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV id="tinyMceEditorPatrick_2" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
    <pubDate>Thu, 26 Mar 2020 06:37:21 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2020-03-26T06:37:21Z</dc:date>
    <item>
      <title>How to assign Jan 1 to Jan 7 in a year as week 1?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-Jan-1-to-Jan-7-in-a-year-as-week-1/m-p/634957#M188486</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How to assign jan 1 as start of week 1 of a year and a week should contain 7 days. i.e, Jan 1 to 7 is a week.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Pls advise.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 26 Mar 2020 04:25:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-Jan-1-to-Jan-7-in-a-year-as-week-1/m-p/634957#M188486</guid>
      <dc:creator>Sandy10</dc:creator>
      <dc:date>2020-03-26T04:25:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign Jan 1 to Jan 7 in a year as week 1?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-Jan-1-to-Jan-7-in-a-year-as-week-1/m-p/634958#M188487</link>
      <description>&lt;P&gt;Does that mean the last week of the year can have less than 7 days? If so then below should work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  format dt date9.;
  input dt:date9.;
  week_in_year=ceil((dt-intnx('year',dt,0,'b')+1)/7);
  datalines;
29dec2019
30dec2019
31dec2019
01jan2020
02jan2020
07jan2020
08jan2020
29dec2020
30dec2020
31dec2020
01jan2021
;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV id="tinyMceEditorPatrick_1" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1585204170027.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/37384i993AC549C7C0F5BF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1585204170027.png" alt="Patrick_0-1585204170027.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV id="tinyMceEditorPatrick_4" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV id="tinyMceEditorPatrick_3" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV id="tinyMceEditorPatrick_2" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Thu, 26 Mar 2020 06:37:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-Jan-1-to-Jan-7-in-a-year-as-week-1/m-p/634958#M188487</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-03-26T06:37:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign Jan 1 to Jan 7 in a year as week 1?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-Jan-1-to-Jan-7-in-a-year-as-week-1/m-p/634959#M188488</link>
      <description>&lt;P&gt;Please explain what you want as output. The week-function has a parameter to define the rules for numbering the first week of a year.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Mar 2020 05:52:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-Jan-1-to-Jan-7-in-a-year-as-week-1/m-p/634959#M188488</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-03-26T05:52:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign Jan 1 to Jan 7 in a year as week 1?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-Jan-1-to-Jan-7-in-a-year-as-week-1/m-p/634978#M188494</link>
      <description>&lt;P&gt;You cam make it this into a function and forget about the logic.&lt;/P&gt;
&lt;P&gt;Reusing &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;'s formula:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fcmp outlib=WORK.FUNCS.DATE;
   function week_from_1jan (DATE);
     return( ceil((DATE-intnx('year',DATE,0,'b')+1)/7) );
   endsub;
run;
   
options cmplib=WORK.FUNCS;

data _null_;
  format DATE date9.;
  input DATE date9.;
  WEEK_IN_YEAR=week_from_1jan(DATE);
  putlog DATE= WEEK_IN_YEAR= ;
datalines;
29dec2019
30dec2019
31dec2019
01jan2020
02jan2020
07jan2020
08jan2020
29dec2020
30dec2020
31dec2020
01jan2021
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="sasSource" style="color: #000000; font-family: Consolas, Courier, 'Courier New'; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: pre; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-decoration-style: initial; text-decoration-color: initial;"&gt;DATE=29DEC2019 WEEK_IN_YEAR=52&lt;/DIV&gt;
&lt;DIV class="sasSource" style="color: #000000; font-family: Consolas, Courier, 'Courier New'; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: pre; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-decoration-style: initial; text-decoration-color: initial;"&gt;DATE=30DEC2019 WEEK_IN_YEAR=52&lt;/DIV&gt;
&lt;DIV class="sasSource" style="color: #000000; font-family: Consolas, Courier, 'Courier New'; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: pre; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-decoration-style: initial; text-decoration-color: initial;"&gt;DATE=31DEC2019 WEEK_IN_YEAR=53&lt;/DIV&gt;
&lt;DIV class="sasSource" style="color: #000000; font-family: Consolas, Courier, 'Courier New'; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: pre; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-decoration-style: initial; text-decoration-color: initial;"&gt;DATE=01JAN2020 WEEK_IN_YEAR=1&lt;/DIV&gt;
&lt;DIV class="sasSource" style="color: #000000; font-family: Consolas, Courier, 'Courier New'; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: pre; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-decoration-style: initial; text-decoration-color: initial;"&gt;DATE=02JAN2020 WEEK_IN_YEAR=1&lt;/DIV&gt;
&lt;DIV class="sasSource" style="color: #000000; font-family: Consolas, Courier, 'Courier New'; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: pre; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-decoration-style: initial; text-decoration-color: initial;"&gt;DATE=07JAN2020 WEEK_IN_YEAR=1&lt;/DIV&gt;
&lt;DIV class="sasSource" style="color: #000000; font-family: Consolas, Courier, 'Courier New'; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: pre; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-decoration-style: initial; text-decoration-color: initial;"&gt;DATE=08JAN2020 WEEK_IN_YEAR=2&lt;/DIV&gt;
&lt;DIV class="sasSource" style="color: #000000; font-family: Consolas, Courier, 'Courier New'; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: pre; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-decoration-style: initial; text-decoration-color: initial;"&gt;DATE=29DEC2020 WEEK_IN_YEAR=52&lt;/DIV&gt;
&lt;DIV class="sasSource" style="color: #000000; font-family: Consolas, Courier, 'Courier New'; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: pre; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-decoration-style: initial; text-decoration-color: initial;"&gt;DATE=30DEC2020 WEEK_IN_YEAR=53&lt;/DIV&gt;
&lt;DIV class="sasSource" style="color: #000000; font-family: Consolas, Courier, 'Courier New'; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: pre; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-decoration-style: initial; text-decoration-color: initial;"&gt;DATE=31DEC2020 WEEK_IN_YEAR=53&lt;/DIV&gt;
&lt;DIV class="sasSource" style="color: #000000; font-family: Consolas, Courier, 'Courier New'; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: pre; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-decoration-style: initial; text-decoration-color: initial;"&gt;DATE=01JAN2021 WEEK_IN_YEAR=1&lt;/DIV&gt;
&lt;DIV class="sasSource" style="color: #000000; font-family: Consolas, Courier, 'Courier New'; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: pre; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-decoration-style: initial; text-decoration-color: initial;"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;Don't store the function in the WORK library though.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Mar 2020 08:51:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-Jan-1-to-Jan-7-in-a-year-as-week-1/m-p/634978#M188494</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-03-26T08:51:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign Jan 1 to Jan 7 in a year as week 1?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-Jan-1-to-Jan-7-in-a-year-as-week-1/m-p/634982#M188497</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Please explain what you want as output. The week-function has a parameter to define the rules for numbering the first week of a year.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;But those only determine if Sunday or Monday is the first day of a week, and if there's a week 0 or those days belong to the previous year.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Mar 2020 09:04:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-Jan-1-to-Jan-7-in-a-year-as-week-1/m-p/634982#M188497</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-03-26T09:04:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign Jan 1 to Jan 7 in a year as week 1?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-Jan-1-to-Jan-7-in-a-year-as-week-1/m-p/634985#M188499</link>
      <description>&lt;P&gt;Use the julday. format:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input dt yymmdd10.;
format dt yymmddd10.;
week = ceil(input(put(dt,julday.),3.)/7);
datalines;
2019-12-31
2020-01-01
2020-01-02
2020-01-03
2020-01-04
2020-01-05
2020-01-06
2020-01-07
2020-01-08
2020-03-26
2020-12-31
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;dt	week
2019-12-31	53
2020-01-01	1
2020-01-02	1
2020-01-03	1
2020-01-04	1
2020-01-05	1
2020-01-06	1
2020-01-07	1
2020-01-08	2
2020-03-26	13
2020-12-31	53
&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Mar 2020 09:08:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-Jan-1-to-Jan-7-in-a-year-as-week-1/m-p/634985#M188499</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-03-26T09:08:01Z</dc:date>
    </item>
  </channel>
</rss>

