<?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: Converting week number to start date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Converting-week-number-to-start-date/m-p/679879#M205350</link>
    <description>&lt;P&gt;Hi Vince,&lt;/P&gt;&lt;P&gt;I found your post from 7years ago. Your method to convert week number to start date seems very cool, but I tried and&amp;nbsp;SAS gave me error message...do you have any tips to fix the error? it is at the part of the second bracket after z2.&amp;nbsp; Thank YOU!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;weekstartdate=input(put(yearnum, 4.)||"W"||put(weeknum,z2.))||"01", weekv9.);&lt;/P&gt;</description>
    <pubDate>Thu, 27 Aug 2020 19:13:48 GMT</pubDate>
    <dc:creator>Flyingbunny</dc:creator>
    <dc:date>2020-08-27T19:13:48Z</dc:date>
    <item>
      <title>Converting week number to start date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-week-number-to-start-date/m-p/106456#M22193</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey,&lt;/P&gt;&lt;P&gt;I have been aggregating data by the week for a reporting suite I'm putting together, and in part of this I have to report on weekly sales by sales channel, on a Monday-Sunday week.&amp;nbsp; So I use the function WEEK(&amp;lt;var&amp;gt;,"w") to pull the week number.&amp;nbsp; But I have such few sales by sales channel, that there may or may not be a sale every Monday.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I am having to create a separate reference table with week number and week start date (using &lt;SPAN class="gm_ gm_5c55b9ef-5849-c426-93ee-936faa913597 gm-spell"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="gm_ gm_b8c3192e-c43b-7379-93d3-ca81ede0a8e9 gm-spell"&gt;sql&lt;/SPAN&gt; and min(order_date) grouped by week(order_date,"w").&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there some way to embed an &lt;SPAN class="gm_ gm_6ccc9ec3-14de-1396-50c2-eaf91e336eb6 gm-spell"&gt;intnx&lt;/SPAN&gt; function with the week function or so, so that I can always return the first date of a week number?&amp;nbsp; Or some other function I just don't know about?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a ton!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Aug 2013 13:13:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-week-number-to-start-date/m-p/106456#M22193</guid>
      <dc:creator>That____Redhead</dc:creator>
      <dc:date>2013-08-09T13:13:49Z</dc:date>
    </item>
    <item>
      <title>Re: Converting week number to start date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-week-number-to-start-date/m-p/106457#M22194</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't think I understand why you need the start date of the week for your application.&lt;/P&gt;&lt;P&gt;Nevertheless, I don't know of any generic way to get the starting day based on the week number.&lt;/P&gt;&lt;P&gt;But to create a lookup table, sure, that should be no problem.&lt;/P&gt;&lt;P&gt;Just start by generating every possible (mon)day, and then generate the week no based on that.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Aug 2013 13:23:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-week-number-to-start-date/m-p/106457#M22194</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2013-08-09T13:23:32Z</dc:date>
    </item>
    <item>
      <title>Re: Converting week number to start date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-week-number-to-start-date/m-p/106458#M22195</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I was hoping to avoid a reference table, and I need the date just to make logical sense of the data on the graphs.&amp;nbsp; Yeah there are other ways to do it, but if I could get it to export the week start date, it'd just be one less step, you know?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your feedback!&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Aug 2013 13:57:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-week-number-to-start-date/m-p/106458#M22195</guid>
      <dc:creator>That____Redhead</dc:creator>
      <dc:date>2013-08-09T13:57:57Z</dc:date>
    </item>
    <item>
      <title>Re: Converting week number to start date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-week-number-to-start-date/m-p/106459#M22196</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You minimally need week number and year to be able to achieve desired results as the start date of a given week varies every year. At least as far as I can tell.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;From weekvw. informat documentation:&lt;/P&gt;&lt;P&gt;&lt;A name="a002604499"&gt;&lt;/A&gt;The WEEKV&lt;SPAN class="emph"&gt;w&lt;/SPAN&gt;. informat reads a &lt;BR /&gt;format of the number-of-week value. &lt;STRONG&gt;If the input does not contain a year &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;expression, WEEKV&lt;SPAN class="emph"&gt;w&lt;/SPAN&gt;. uses the current year as the year &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;expression, which is the default. If the input does not contain a day &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;expression, WEEKV&lt;SPAN class="emph"&gt;w&lt;/SPAN&gt;. uses the first day of the week as &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;the day expression, which is the default. &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's how it can be done if you have both in variables. You can replace the put(yearnum, 4.) by "2013" or whatever if your year is fixed accross your entire dataset and don't have a year variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input dt date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; datalines;&lt;/P&gt;&lt;P&gt;01JAN2011&lt;/P&gt;&lt;P&gt;02JAN2011&lt;/P&gt;&lt;P&gt;03JAN2011&lt;/P&gt;&lt;P&gt;04JAN2011&lt;/P&gt;&lt;P&gt;05JAN2011&lt;/P&gt;&lt;P&gt;06JAN2011&lt;/P&gt;&lt;P&gt;07JAN2011&lt;/P&gt;&lt;P&gt;08JAN2011&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; weeknum=week(dt, "w");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; yearnum=year(dt);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; weekstartdate=input(put(yearnum, 4.)||"W"||put(weeknum,z2.))||"01", weekv9.);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Vince&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Aug 2013 14:09:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-week-number-to-start-date/m-p/106459#M22196</guid>
      <dc:creator>Vince28_Statcan</dc:creator>
      <dc:date>2013-08-09T14:09:41Z</dc:date>
    </item>
    <item>
      <title>Re: Converting week number to start date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-week-number-to-start-date/m-p/106460#M22197</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If I understand correctly, you already have a SAS date stored in VAR, and you want the SAS date that corresponds to the most recent Monday.&amp;nbsp; If that's the case, the week number doesn't matter.&amp;nbsp; You can calculate what you need based on VAR.&amp;nbsp; Here's one way:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;week_begins = var - weekday(var) + 1 - 7*(weekday(var)=0);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Perhaps I'm solving the wrong problem??&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Aug 2013 20:23:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-week-number-to-start-date/m-p/106460#M22197</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2013-08-09T20:23:35Z</dc:date>
    </item>
    <item>
      <title>Re: Converting week number to start date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-week-number-to-start-date/m-p/106461#M22198</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think that using Intnx-function is the easiest way to solve this. With 'Week.2' you are setting your weeks starting from Monday:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; monday=intnx('week.2',dt,0);&lt;/P&gt;&lt;P&gt;&amp;nbsp; week=week(monday);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Aug 2013 12:55:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-week-number-to-start-date/m-p/106461#M22198</guid>
      <dc:creator>AskoLötjönen</dc:creator>
      <dc:date>2013-08-12T12:55:56Z</dc:date>
    </item>
    <item>
      <title>Re: Converting week number to start date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-week-number-to-start-date/m-p/106462#M22199</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If i understand you correctly, you don't really want week number but the week start or the previous Monday's date in each of your records.&lt;/P&gt;&lt;P&gt;if you have a variable DATE for the date of each sale then&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if weekday(date)=1 then weekstart=date-6;else&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; weekstart=date-weekday(date)+2;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;will put the previous Mondays date in weekstart&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope it's what you need&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Aug 2013 15:22:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-week-number-to-start-date/m-p/106462#M22199</guid>
      <dc:creator>ChrisSelley</dc:creator>
      <dc:date>2013-08-15T15:22:06Z</dc:date>
    </item>
    <item>
      <title>Re: Converting week number to start date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-week-number-to-start-date/m-p/679879#M205350</link>
      <description>&lt;P&gt;Hi Vince,&lt;/P&gt;&lt;P&gt;I found your post from 7years ago. Your method to convert week number to start date seems very cool, but I tried and&amp;nbsp;SAS gave me error message...do you have any tips to fix the error? it is at the part of the second bracket after z2.&amp;nbsp; Thank YOU!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;weekstartdate=input(put(yearnum, 4.)||"W"||put(weeknum,z2.))||"01", weekv9.);&lt;/P&gt;</description>
      <pubDate>Thu, 27 Aug 2020 19:13:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-week-number-to-start-date/m-p/679879#M205350</guid>
      <dc:creator>Flyingbunny</dc:creator>
      <dc:date>2020-08-27T19:13:48Z</dc:date>
    </item>
  </channel>
</rss>

