<?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: Convert full date to year and week of the year? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Convert-full-date-to-year-and-week-of-the-year/m-p/66394#M18968</link>
    <description>SAS has a number of date functions and formats that you could use to solve your problem.  Try the WEEK function or WEEKU./WEEKW. formats&lt;BR /&gt;
&lt;BR /&gt;
Try looking at the documentation&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a003154994.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a003154994.htm&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002604217.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002604217.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
below is a quite example for week begining with Sunday&lt;BR /&gt;
&lt;BR /&gt;
data one;&lt;BR /&gt;
format raw_date yymmddp10.;&lt;BR /&gt;
input raw_date yymmdd10.;&lt;BR /&gt;
datalines;&lt;BR /&gt;
2009.01.05&lt;BR /&gt;
2009.01.06&lt;BR /&gt;
2010.01.05&lt;BR /&gt;
2011.01.05&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data two;&lt;BR /&gt;
  set one;&lt;BR /&gt;
  format myweek weeku6.;&lt;BR /&gt;
  myweek=raw_date;&lt;BR /&gt;
run;</description>
    <pubDate>Tue, 17 May 2011 14:50:54 GMT</pubDate>
    <dc:creator>darrylovia</dc:creator>
    <dc:date>2011-05-17T14:50:54Z</dc:date>
    <item>
      <title>Convert full date to year and week of the year?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-full-date-to-year-and-week-of-the-year/m-p/66392#M18966</link>
      <description>Ok, let's say I have imported retail sales dataset with date formated like this:&lt;BR /&gt;
&lt;BR /&gt;
2009.01.05&lt;BR /&gt;
2009.01.06&lt;BR /&gt;
...&lt;BR /&gt;
2010.01.05&lt;BR /&gt;
...&lt;BR /&gt;
2011.01.05&lt;BR /&gt;
&lt;BR /&gt;
I want to work with weekly results of sales, how to I convert this date format to something like this:&lt;BR /&gt;
2009w1&lt;BR /&gt;
2009w1&lt;BR /&gt;
...&lt;BR /&gt;
2010w1&lt;BR /&gt;
...&lt;BR /&gt;
2011w1&lt;BR /&gt;
etc...&lt;BR /&gt;
&lt;BR /&gt;
Or if that's not possible, maybe change date to corresponding weeks Sunday date.&lt;BR /&gt;
for example if 2009.01.19 is 2nd weeks Saturday, change all dates:&lt;BR /&gt;
2009.01.13&lt;BR /&gt;
2009.01.14&lt;BR /&gt;
2009.01.15&lt;BR /&gt;
2009.01.16&lt;BR /&gt;
2009.01.17&lt;BR /&gt;
2009.01.18&lt;BR /&gt;
&lt;BR /&gt;
to 2009.01.19&lt;BR /&gt;
&lt;BR /&gt;
Help much appreciated.&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: efunk

Message was edited by: efunk</description>
      <pubDate>Tue, 17 May 2011 14:28:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-full-date-to-year-and-week-of-the-year/m-p/66392#M18966</guid>
      <dc:creator>efunk</dc:creator>
      <dc:date>2011-05-17T14:28:39Z</dc:date>
    </item>
    <item>
      <title>Re: Convert full date to year and week of the year?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-full-date-to-year-and-week-of-the-year/m-p/66393#M18967</link>
      <description>Hello Efunk,&lt;BR /&gt;
&lt;BR /&gt;
Is this what you need?&lt;BR /&gt;
[pre]&lt;BR /&gt;
data i; &lt;BR /&gt;
  input date ANYDTDTE10.;&lt;BR /&gt;
  format date YYMMDDP10.;&lt;BR /&gt;
  date1=SUBSTR(put(date,WEEKU9.),1,6);&lt;BR /&gt;
datalines; &lt;BR /&gt;
2009.01.05&lt;BR /&gt;
2009.01.06&lt;BR /&gt;
2010.01.05&lt;BR /&gt;
2011.01.05&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Sincerely,&lt;BR /&gt;
SPR</description>
      <pubDate>Tue, 17 May 2011 14:43:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-full-date-to-year-and-week-of-the-year/m-p/66393#M18967</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2011-05-17T14:43:47Z</dc:date>
    </item>
    <item>
      <title>Re: Convert full date to year and week of the year?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-full-date-to-year-and-week-of-the-year/m-p/66394#M18968</link>
      <description>SAS has a number of date functions and formats that you could use to solve your problem.  Try the WEEK function or WEEKU./WEEKW. formats&lt;BR /&gt;
&lt;BR /&gt;
Try looking at the documentation&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a003154994.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a003154994.htm&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002604217.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002604217.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
below is a quite example for week begining with Sunday&lt;BR /&gt;
&lt;BR /&gt;
data one;&lt;BR /&gt;
format raw_date yymmddp10.;&lt;BR /&gt;
input raw_date yymmdd10.;&lt;BR /&gt;
datalines;&lt;BR /&gt;
2009.01.05&lt;BR /&gt;
2009.01.06&lt;BR /&gt;
2010.01.05&lt;BR /&gt;
2011.01.05&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data two;&lt;BR /&gt;
  set one;&lt;BR /&gt;
  format myweek weeku6.;&lt;BR /&gt;
  myweek=raw_date;&lt;BR /&gt;
run;</description>
      <pubDate>Tue, 17 May 2011 14:50:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-full-date-to-year-and-week-of-the-year/m-p/66394#M18968</guid>
      <dc:creator>darrylovia</dc:creator>
      <dc:date>2011-05-17T14:50:54Z</dc:date>
    </item>
    <item>
      <title>Re: Convert full date to year and week of the year?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-full-date-to-year-and-week-of-the-year/m-p/66395#M18969</link>
      <description>Both of your methods works good.&lt;BR /&gt;
I went with darrylovia's method.&lt;BR /&gt;
&lt;BR /&gt;
Thank you, guys.</description>
      <pubDate>Tue, 17 May 2011 14:59:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-full-date-to-year-and-week-of-the-year/m-p/66395#M18969</guid>
      <dc:creator>efunk</dc:creator>
      <dc:date>2011-05-17T14:59:18Z</dc:date>
    </item>
    <item>
      <title>Re: Convert full date to year and week of the year?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-full-date-to-year-and-week-of-the-year/m-p/66396#M18970</link>
      <description>Ok, I might have been to excited about this and jumped to the conclusions too quickly.&lt;BR /&gt;
SPR, your method isn't working as it should, I'm getting W0(there is no such thing as week 0), and only up to W5 in the whole year. I'm guessing it converted to something else.&lt;BR /&gt;
&lt;BR /&gt;
And darrylovia, maybe you know, why proc SQL doesn't group by with your format?</description>
      <pubDate>Tue, 17 May 2011 15:10:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-full-date-to-year-and-week-of-the-year/m-p/66396#M18970</guid>
      <dc:creator>efunk</dc:creator>
      <dc:date>2011-05-17T15:10:32Z</dc:date>
    </item>
    <item>
      <title>Re: Convert full date to year and week of the year?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-full-date-to-year-and-week-of-the-year/m-p/66397#M18971</link>
      <description>Sorry it is a typo in my code. Should be  &lt;BR /&gt;
date1=SUBSTR(put(date,WEEKU9.),1,7);&lt;BR /&gt;
SPR</description>
      <pubDate>Tue, 17 May 2011 15:41:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-full-date-to-year-and-week-of-the-year/m-p/66397#M18971</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2011-05-17T15:41:23Z</dc:date>
    </item>
    <item>
      <title>Re: Convert full date to year and week of the year?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-full-date-to-year-and-week-of-the-year/m-p/66398#M18972</link>
      <description>Works like a charm this time.&lt;BR /&gt;
Thank you, SPR.</description>
      <pubDate>Tue, 17 May 2011 16:40:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-full-date-to-year-and-week-of-the-year/m-p/66398#M18972</guid>
      <dc:creator>efunk</dc:creator>
      <dc:date>2011-05-17T16:40:34Z</dc:date>
    </item>
    <item>
      <title>Re: Convert full date to year and week of the year?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-full-date-to-year-and-week-of-the-year/m-p/66399#M18973</link>
      <description>Just convert the date to a character like below&lt;BR /&gt;
&lt;BR /&gt;
data two;&lt;BR /&gt;
  set one;&lt;BR /&gt;
  format myweek weeku6.;&lt;BR /&gt;
  myweek=raw_date;&lt;BR /&gt;
  cat_week=put(raw_date,weeku6.);&lt;BR /&gt;
run;</description>
      <pubDate>Tue, 17 May 2011 17:58:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-full-date-to-year-and-week-of-the-year/m-p/66399#M18973</guid>
      <dc:creator>darrylovia</dc:creator>
      <dc:date>2011-05-17T17:58:15Z</dc:date>
    </item>
  </channel>
</rss>

