<?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: Finding Week Number of a Month in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Finding-Week-Number-of-a-Month/m-p/613882#M179363</link>
    <description>&lt;P&gt;Or you could count the number of Sunday.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
n=0;
date='26dec2019'd;
do i=intnx('month',date,0) to date;
 if weekday(i)=1 then n+1;
end;
put n=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 26 Dec 2019 11:42:50 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2019-12-26T11:42:50Z</dc:date>
    <item>
      <title>Finding Week Number of a Month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Week-Number-of-a-Month/m-p/613851#M179343</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset with weekly observations for all variables. The format of "Date_week" is "mmddyy10." For every variable, I have one observation per week, but it is not necessarily the last working day of the week.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to find out "week number" for every month. I have used following code, but it does not give me the exact week number for the dates that are not the last working day (Friday) of a week.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please guide me in this regard. Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tmp1;
set tmp;
Week = ceil( day(Date_week) / 7); run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Dec 2019 05:06:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Week-Number-of-a-Month/m-p/613851#M179343</guid>
      <dc:creator>Saba1</dc:creator>
      <dc:date>2019-12-26T05:06:49Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Week Number of a Month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Week-Number-of-a-Month/m-p/613854#M179345</link>
      <description>&lt;P&gt;If you have weekly data then it may be more useful and definitely easier to explore the SAS WEEK function which will give you the week number in a year. There are different definitions for this so you can choose the one which is most appropriate to your requirements:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=n1ka2ulrvrjlasn0z7beco2yrgas.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=n1ka2ulrvrjlasn0z7beco2yrgas.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Week number in a month is likely to cause boundary problems because of the varying number of days in each month. The WEEK function takes care of those types of problems, including dealing with leap years.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Dec 2019 05:45:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Week-Number-of-a-Month/m-p/613854#M179345</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-12-26T05:45:45Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Week Number of a Month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Week-Number-of-a-Month/m-p/613880#M179361</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
date='26dec2019'd;
n=week(date,'u')-week(intnx('month',date,-1,'e'),'u');
/*
n=week(date,'v')-week(intnx('month',date,-1,'e'),'v');
*/
put n=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Dec 2019 11:37:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Week-Number-of-a-Month/m-p/613880#M179361</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-12-26T11:37:26Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Week Number of a Month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Week-Number-of-a-Month/m-p/613882#M179363</link>
      <description>&lt;P&gt;Or you could count the number of Sunday.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
n=0;
date='26dec2019'd;
do i=intnx('month',date,0) to date;
 if weekday(i)=1 then n+1;
end;
put n=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Dec 2019 11:42:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Week-Number-of-a-Month/m-p/613882#M179363</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-12-26T11:42:50Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Week Number of a Month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Week-Number-of-a-Month/m-p/614047#M179433</link>
      <description>Thank you so much</description>
      <pubDate>Fri, 27 Dec 2019 10:36:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Week-Number-of-a-Month/m-p/614047#M179433</guid>
      <dc:creator>Saba1</dc:creator>
      <dc:date>2019-12-27T10:36:38Z</dc:date>
    </item>
  </channel>
</rss>

