<?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 get the week number in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-get-the-week-number/m-p/771210#M39636</link>
    <description>&lt;P&gt;I am looking the the week number of September, 23 2021 which is suppose to be 38 while I am getting a 23&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 29 Sep 2021 19:07:24 GMT</pubDate>
    <dc:creator>alepage</dc:creator>
    <dc:date>2021-09-29T19:07:24Z</dc:date>
    <item>
      <title>how to get the week number</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-get-the-week-number/m-p/771196#M39633</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have found an example on the web how to use the week function and for 2021-09-23, I obtain week number 38.&amp;nbsp; But when I use a macro variable and sysfunc, I am getting 23.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do we solve that issue?&lt;/P&gt;
&lt;PRE&gt;data work.dates1;
	format my_date YYMMDD10.;
	input my_date date9.;
	datalines;
08JAN2019
26JUN2020
05DEC2020
23SEP2021
;
run;

data work.dates_extract;
	set work.dates1;
 
	my_year = year(my_date);
	my_quarter = qtr(my_date);
	my_month = month(my_date);
	my_week = week(my_date);
	my_day = day(my_date);
run;

%let date=2021-09-23;
%put %sysfunc(week(&amp;amp;date.,w));&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Sep 2021 18:30:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-get-the-week-number/m-p/771196#M39633</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2021-09-29T18:30:16Z</dc:date>
    </item>
    <item>
      <title>Re: how to get the week number</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-get-the-week-number/m-p/771202#M39634</link>
      <description>&lt;PRE&gt;%let date=2021-09-23;&lt;/PRE&gt;
&lt;P&gt;That is not a SAS date, and will not be interpreted as such.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%put %sysfunc(week(&amp;amp;date.,w));&lt;/PRE&gt;
&lt;P&gt;Your function here has a second parameter, W&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	my_week = week(my_date);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;However your function in the data step does not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Fixing those will resolve your issues.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76331"&gt;@alepage&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have found an example on the web how to use the week function and for 2021-09-23, I obtain week number 38.&amp;nbsp; But when I use a macro variable and sysfunc, I am getting 23.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do we solve that issue?&lt;/P&gt;
&lt;PRE&gt;data work.dates1;
	format my_date YYMMDD10.;
	input my_date date9.;
	datalines;
08JAN2019
26JUN2020
05DEC2020
23SEP2021
;
run;

data work.dates_extract;
	set work.dates1;
 
	my_year = year(my_date);
	my_quarter = qtr(my_date);
	my_month = month(my_date);
	my_week = week(my_date);
	my_day = day(my_date);
run;

%let date=2021-09-23;
%put %sysfunc(week(&amp;amp;date.,w));&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Sep 2021 18:50:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-get-the-week-number/m-p/771202#M39634</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-09-29T18:50:18Z</dc:date>
    </item>
    <item>
      <title>Re: how to get the week number</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-get-the-week-number/m-p/771207#M39635</link>
      <description>&lt;P&gt;If you perform the subtraction you requested you get the number 1,989.&lt;/P&gt;
&lt;P&gt;To see why that is week number 23 check what calendar date the number 1,989 represents.&lt;/P&gt;
&lt;PRE&gt;227   data _null_;
228     date=2021-09-23;
229     week= week(date,'w');
230     put date= week=;
231     put date= date9. +1 date yymmdd10. ;
232   run;

date=1989 week=23
date=12JUN1965  1965-06-12
&lt;/PRE&gt;
&lt;P&gt;So week number 23 sounds about right for the middle of June.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Sep 2021 19:03:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-get-the-week-number/m-p/771207#M39635</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-29T19:03:05Z</dc:date>
    </item>
    <item>
      <title>Re: how to get the week number</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-get-the-week-number/m-p/771210#M39636</link>
      <description>&lt;P&gt;I am looking the the week number of September, 23 2021 which is suppose to be 38 while I am getting a 23&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Sep 2021 19:07:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-get-the-week-number/m-p/771210#M39636</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2021-09-29T19:07:24Z</dc:date>
    </item>
    <item>
      <title>Re: how to get the week number</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-get-the-week-number/m-p/771213#M39637</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76331"&gt;@alepage&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am looking the the week number of September, 23 2021 which is suppose to be 38 while I am getting a 23&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then why didn't you tell SAS to use that date instead of the one from 1965 you did use?&lt;/P&gt;
&lt;PRE&gt;233   data _null_;
234     date='23SEP2021'd;
235     week= week(date,'w');
236     put date= week=;
237     put date= date9. +1 date yymmdd10. ;
238   run;

date=22546 week=38
date=23SEP2021  2021-09-23
&lt;/PRE&gt;
&lt;P&gt;You can either put the date literal or the actual number of days into your macro variable.&lt;/P&gt;
&lt;PRE&gt;247   %let date="23SEP2021"d;
248   %let week=%sysfunc(week(&amp;amp;date.,w));
249   %put &amp;amp;=week;
WEEK=38
250   %let date=22546;
251   %let week=%sysfunc(week(&amp;amp;date.,w));
252   %put &amp;amp;=week;
WEEK=38
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Sep 2021 19:12:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-get-the-week-number/m-p/771213#M39637</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-29T19:12:07Z</dc:date>
    </item>
    <item>
      <title>Re: how to get the week number</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-get-the-week-number/m-p/771217#M39638</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76331"&gt;@alepage&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am looking the the week number of September, 23 2021 which is suppose to be 38 while I am getting a 23&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;PRE&gt;%let date=2021-09-23;&lt;/PRE&gt;
&lt;P&gt;That is not a SAS date, and will not be interpreted as such.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That is interpreted as SUBTRACTION -&amp;gt; 2021-9-23 = 1989.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is true in macros or non-macro code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try using the SAS literal that is used elsewhere instead or the MDY function if you want.&lt;/P&gt;
&lt;P&gt;Then the rest of your code will work.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date=%sysfunc(mdy(9, 23, 2021));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Sep 2021 19:29:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-get-the-week-number/m-p/771217#M39638</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-09-29T19:29:13Z</dc:date>
    </item>
    <item>
      <title>Re: how to get the week number</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-get-the-week-number/m-p/771219#M39639</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date=2021-09-23;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;amp;date is a text string whose value is 2021-09-23, it is not interpreted as a date because that's not how SAS works with dates. So, it's not a date, and thus you shouldn't expect the right answer from the WEEK function.&amp;nbsp;In SAS, dates are the number of days since 01JAN1960.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want a macro variable that has the date value of September 23, 2021, which is 22546 days since 01JAN1960, you can use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date= %sysevalf('23SEP2021'd);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and now SAS can work with this value, and produce the proper week calculation.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Sep 2021 19:46:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-get-the-week-number/m-p/771219#M39639</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-09-29T19:46:24Z</dc:date>
    </item>
  </channel>
</rss>

