<?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 Assigning Weeks in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Assigning-Weeks/m-p/865318#M38237</link>
    <description>&lt;P&gt;Hi there,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a fairly large dataset (data=have)with dates that spans from April 5, 2021 to December 31, 2022.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know the SAS date function usually assigns the week number based on the start of the year. However, I was wondering if there was another way to automatically assign a week number to each record in my dataset where 05Apr2021 to 11Apr2021 would be assigned week 1 (not week 0 ),&amp;nbsp; 12Apr2021 to 17Apr2021 would be assigned week 2, and so forth.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Obs&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Week&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 05APR2021&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1002&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;19 APR2021&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2040&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01JAN2022&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;7680&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;08APR2021&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5432&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 30DEC2022&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 20 Mar 2023 23:09:22 GMT</pubDate>
    <dc:creator>jnivi</dc:creator>
    <dc:date>2023-03-20T23:09:22Z</dc:date>
    <item>
      <title>Assigning Weeks</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Assigning-Weeks/m-p/865318#M38237</link>
      <description>&lt;P&gt;Hi there,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a fairly large dataset (data=have)with dates that spans from April 5, 2021 to December 31, 2022.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know the SAS date function usually assigns the week number based on the start of the year. However, I was wondering if there was another way to automatically assign a week number to each record in my dataset where 05Apr2021 to 11Apr2021 would be assigned week 1 (not week 0 ),&amp;nbsp; 12Apr2021 to 17Apr2021 would be assigned week 2, and so forth.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Obs&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Week&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 05APR2021&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1002&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;19 APR2021&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2040&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01JAN2022&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;7680&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;08APR2021&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5432&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 30DEC2022&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Mar 2023 23:09:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Assigning-Weeks/m-p/865318#M38237</guid>
      <dc:creator>jnivi</dc:creator>
      <dc:date>2023-03-20T23:09:22Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning Weeks</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Assigning-Weeks/m-p/865319#M38238</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select min(date) into :begin
from have;
quit;

data want;
set have;
week = intck(`week`,&amp;amp;begin.,date,'c') + 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 Mar 2023 22:58:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Assigning-Weeks/m-p/865319#M38238</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-03-20T22:58:14Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning Weeks</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Assigning-Weeks/m-p/865766#M38253</link>
      <description>&lt;P&gt;Although the code&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;has supplied works for the example data provided. You also need to be aware that it ONLY works assuming your input data earliest observation has date="05APR2021"d&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;If you were to run this code against another dataset that which has a different value earliest value for date, e.g. 01APR2021 then week 1 is going to be 01APR2021- 07APR2021.&lt;BR /&gt;&lt;BR /&gt;If you want have consistent behavior where week 1 is always 05APR2021-11APR2021 then you are going to want to remove the PROC SQL step and hard code your starting date (&amp;amp;begin)&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p1md4mx2crzfaqn14va8kt7qvfhr.htm" target="_self"&gt;INTCK Function&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
	format date date7. ;
	do i=3 to 100 by 3 ;
		date="04APR2021"d+i  ;
		output have ;
	end ;
run ;

proc sort data=have ;
	by date ;
run ;

data want;
	set have;
	week=intck("week","05APR2021"d,date,'c') + 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Mar 2023 15:55:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Assigning-Weeks/m-p/865766#M38253</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2023-03-22T15:55:41Z</dc:date>
    </item>
  </channel>
</rss>

