<?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: Consecutive week number based on date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Consecutive-week-number-based-on-date/m-p/633253#M187843</link>
    <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&lt;BR /&gt;Perfect, thanks!</description>
    <pubDate>Thu, 19 Mar 2020 12:51:28 GMT</pubDate>
    <dc:creator>chris2377</dc:creator>
    <dc:date>2020-03-19T12:51:28Z</dc:date>
    <item>
      <title>Consecutive week number based on date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Consecutive-week-number-based-on-date/m-p/633246#M187839</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a long series of data, recorded daily from Monday to Friday. I'd like to add a variable that numbers consecutive weeks - it will equal 1 for the first 5 obs, 2 for observations 6-10 etc. (like in the example below). How to do it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
		input date :yymmdd10.;
		format date yymmdd10.;
		datalines;
		2020-01-06
		2020-01-07
		2020-01-08
		2020-01-09
		2020-01-10
		2020-01-13
		2020-01-14
		2020-01-15
		2020-01-16
		2020-01-17
		2020-01-20
		2020-01-21
		2020-01-22
		2020-01-23
		2020-01-24
		;
	run;

	data want;
		input date :yymmdd10. week_no;
		format date yymmdd10.;
		datalines;
		2020-01-06 1
		2020-01-07 1
		2020-01-08 1
		2020-01-09 1
		2020-01-10 1
		2020-01-13 2
		2020-01-14 2
		2020-01-15 2
		2020-01-16 2
		2020-01-17 2
		2020-01-20 3
		2020-01-21 3
		2020-01-22 3
		2020-01-23 3
		2020-01-24 3
		;
	run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Best&lt;/P&gt;</description>
      <pubDate>Thu, 19 Mar 2020 12:41:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Consecutive-week-number-based-on-date/m-p/633246#M187839</guid>
      <dc:creator>chris2377</dc:creator>
      <dc:date>2020-03-19T12:41:39Z</dc:date>
    </item>
    <item>
      <title>Re: Consecutive week number based on date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Consecutive-week-number-based-on-date/m-p/633251#M187841</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;w = week(date);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Mar 2020 12:46:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Consecutive-week-number-based-on-date/m-p/633251#M187841</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2020-03-19T12:46:36Z</dc:date>
    </item>
    <item>
      <title>Re: Consecutive week number based on date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Consecutive-week-number-based-on-date/m-p/633252#M187842</link>
      <description>&lt;P&gt;How about&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input date :yymmdd10.;
format date yymmdd10.;
datalines;
2020-01-06
2020-01-07
2020-01-08
2020-01-09
2020-01-10
2020-01-13
2020-01-14
2020-01-15
2020-01-16
2020-01-17
2020-01-20
2020-01-21
2020-01-22
2020-01-23
2020-01-24
;

data want;
   set have;
   if mod(_N_, 5) = 1 then weekno + 1;
run;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Mar 2020 12:47:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Consecutive-week-number-based-on-date/m-p/633252#M187842</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-03-19T12:47:40Z</dc:date>
    </item>
    <item>
      <title>Re: Consecutive week number based on date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Consecutive-week-number-based-on-date/m-p/633253#M187843</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&lt;BR /&gt;Perfect, thanks!</description>
      <pubDate>Thu, 19 Mar 2020 12:51:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Consecutive-week-number-based-on-date/m-p/633253#M187843</guid>
      <dc:creator>chris2377</dc:creator>
      <dc:date>2020-03-19T12:51:28Z</dc:date>
    </item>
    <item>
      <title>Re: Consecutive week number based on date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Consecutive-week-number-based-on-date/m-p/633255#M187845</link>
      <description>&lt;P&gt;Anytime. My code is a direct solution to your specific problem. I must address, that you should take advatage of the &lt;A href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=n1ka2ulrvrjlasn0z7beco2yrgas.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;week() function&lt;/A&gt;&amp;nbsp;if applicable.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Mar 2020 12:53:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Consecutive-week-number-based-on-date/m-p/633255#M187845</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-03-19T12:53:20Z</dc:date>
    </item>
    <item>
      <title>Re: Consecutive week number based on date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Consecutive-week-number-based-on-date/m-p/633256#M187846</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;&lt;BR /&gt;I've tried that first, but it doesn't work properly when there's a year change</description>
      <pubDate>Thu, 19 Mar 2020 12:53:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Consecutive-week-number-based-on-date/m-p/633256#M187846</guid>
      <dc:creator>chris2377</dc:creator>
      <dc:date>2020-03-19T12:53:20Z</dc:date>
    </item>
    <item>
      <title>Re: Consecutive week number based on date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Consecutive-week-number-based-on-date/m-p/633257#M187847</link>
      <description>&lt;P&gt;I guess I have concerns about both of the above solutions, as it could be possible that they fail in certain situations. In particular, relying on _N_ requires that there always be five days listed for each week; if a day isn't listed because its a holiday, then this method fails. The WEEK function works fine within a year, but if the data set is 53 or more weeks long, then (for example), Jan 3 2020 and Jan 3 2021 would be the same week.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would use the INTCK function to determine the number of weeks after the first date.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Mar 2020 12:53:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Consecutive-week-number-based-on-date/m-p/633257#M187847</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-03-19T12:53:38Z</dc:date>
    </item>
  </channel>
</rss>

