<?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: I'm looking for a function that can tell me what week in the month a given data date is from. in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/I-m-looking-for-a-function-that-can-tell-me-what-week-in-the/m-p/407148#M12417</link>
    <description>&lt;P&gt;Excel files are USELESS(!) as example data. Excel files are unstructured dungheaps of garbage. No attributes, nothing.&lt;/P&gt;
&lt;P&gt;Quote from &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;' post: "Please post sample data as data-step."&lt;/P&gt;
&lt;P&gt;Use the macro from&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; to convert your dataset to a data step, or write your own.&lt;/P&gt;
&lt;P&gt;How to post code is found here: &lt;A href="https://communities.sas.com/t5/help/faqpage/faq-category-id/posting#posting" target="_blank"&gt;https://communities.sas.com/t5/help/faqpage/faq-category-id/posting#posting&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 25 Oct 2017 07:50:35 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-10-25T07:50:35Z</dc:date>
    <item>
      <title>I'm looking for a function that can tell me what week in the month a given data date is from.</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/I-m-looking-for-a-function-that-can-tell-me-what-week-in-the/m-p/407135#M12412</link>
      <description>&lt;P&gt;I'm looking for a function that can tell me what week in the month a given data date is from.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have weekly data&amp;nbsp;that spans for&amp;nbsp;two years. The data begins from the third week of May 2015. Now, there are some unbalanced structures of duplicate data. What I want to do is to keep all of the duplicate dates four weeks following the third week of May.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, there are instances in which four weeks ahead of that initial date will end in the same month. I want to account for this by creating an exception where, if this is true, it will use five weeks ahead instead of the usual four.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know I can use an if statement to accomplish this, but I am unsure how to do this.&lt;/P&gt;&lt;P&gt;I posted my SAS data file. The variable I need to deal with in this file is called _datadate. The problem happens in the following example:&lt;/P&gt;&lt;P&gt;10/02/2015&amp;nbsp;&lt;/P&gt;&lt;P&gt;four weeks later:&lt;/P&gt;&lt;P&gt;10/30/2015&lt;/P&gt;&lt;P&gt;This displays my problem. It shouldn't land in the same month. I would want it to go to 11/06/2015.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you and have a good day.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2017 06:17:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/I-m-looking-for-a-function-that-can-tell-me-what-week-in-the/m-p/407135#M12412</guid>
      <dc:creator>Xinhui</dc:creator>
      <dc:date>2017-10-25T06:17:09Z</dc:date>
    </item>
    <item>
      <title>Re: I'm looking for a function that can tell me what week in the month a given data date is from.</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/I-m-looking-for-a-function-that-can-tell-me-what-week-in-the/m-p/407139#M12413</link>
      <description>&lt;P&gt;Sorry, but i don't understand the problem. Please post sample data as data-step.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2017 07:03:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/I-m-looking-for-a-function-that-can-tell-me-what-week-in-the/m-p/407139#M12413</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2017-10-25T07:03:52Z</dc:date>
    </item>
    <item>
      <title>Re: I'm looking for a function that can tell me what week in the month a given data date is from.</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/I-m-looking-for-a-function-that-can-tell-me-what-week-in-the/m-p/407146#M12415</link>
      <description>&lt;P&gt;I hope this sample can make you understand what I thought.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2017 07:33:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/I-m-looking-for-a-function-that-can-tell-me-what-week-in-the/m-p/407146#M12415</guid>
      <dc:creator>Xinhui</dc:creator>
      <dc:date>2017-10-25T07:33:41Z</dc:date>
    </item>
    <item>
      <title>Re: I'm looking for a function that can tell me what week in the month a given data date is from.</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/I-m-looking-for-a-function-that-can-tell-me-what-week-in-the/m-p/407147#M12416</link>
      <description />
      <pubDate>Wed, 25 Oct 2017 07:37:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/I-m-looking-for-a-function-that-can-tell-me-what-week-in-the/m-p/407147#M12416</guid>
      <dc:creator>Xinhui</dc:creator>
      <dc:date>2017-10-25T07:37:08Z</dc:date>
    </item>
    <item>
      <title>Re: I'm looking for a function that can tell me what week in the month a given data date is from.</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/I-m-looking-for-a-function-that-can-tell-me-what-week-in-the/m-p/407148#M12417</link>
      <description>&lt;P&gt;Excel files are USELESS(!) as example data. Excel files are unstructured dungheaps of garbage. No attributes, nothing.&lt;/P&gt;
&lt;P&gt;Quote from &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;' post: "Please post sample data as data-step."&lt;/P&gt;
&lt;P&gt;Use the macro from&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; to convert your dataset to a data step, or write your own.&lt;/P&gt;
&lt;P&gt;How to post code is found here: &lt;A href="https://communities.sas.com/t5/help/faqpage/faq-category-id/posting#posting" target="_blank"&gt;https://communities.sas.com/t5/help/faqpage/faq-category-id/posting#posting&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2017 07:50:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/I-m-looking-for-a-function-that-can-tell-me-what-week-in-the/m-p/407148#M12417</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-25T07:50:35Z</dc:date>
    </item>
    <item>
      <title>Re: I'm looking for a function that can tell me what week in the month a given data date is from.</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/I-m-looking-for-a-function-that-can-tell-me-what-week-in-the/m-p/407149#M12418</link>
      <description>&lt;P&gt;The DAY function returns the day of the month (1 through 31).&amp;nbsp; That should support the calculations you describe.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2017 07:53:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/I-m-looking-for-a-function-that-can-tell-me-what-week-in-the/m-p/407149#M12418</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-10-25T07:53:58Z</dc:date>
    </item>
    <item>
      <title>Re: I'm looking for a function that can tell me what week in the month a given data date is from.</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/I-m-looking-for-a-function-that-can-tell-me-what-week-in-the/m-p/407189#M12419</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/124145"&gt;@Xinhui&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Looking at your sample data (the column with the date you want) doesn't really marry up with your explanation of the logic you're after. At least I can't make sense of it. For this reason below code won't be the solution for you. May be it gives you at least some ideas.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sample;
  infile datalines truncover dlm=' ';
  input (dt_have dt_tst) (:mmddyy10.);
  format dt_have dt_tst dt_want date9.;

  dt_want=intnx('week',dt_have,4,'s');
  if intck('month',dt_have,dt_want)=0 then dt_want=intnx('week',dt_have,5,'s');
  datalines;
05/15/2015 05/15/2015
05/15/2015 05/15/2015
05/15/2015 05/15/2015
05/22/2015 06/12/2015
05/22/2015 06/12/2015
05/29/2015 06/12/2015
05/29/2015 06/12/2015
05/29/2015 07/10/2015
05/29/2015 07/10/2015
05/29/2015 08/07/2015
06/05/2015 08/07/2015
06/05/2015 08/07/2015
06/05/2015 09/04/2015
06/12/2015 10/02/2015
06/12/2015 10/02/2015
06/12/2015 11/06/2015
06/12/2015 11/06/2015
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Oct 2017 10:22:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/I-m-looking-for-a-function-that-can-tell-me-what-week-in-the/m-p/407189#M12419</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-10-25T10:22:58Z</dc:date>
    </item>
    <item>
      <title>Re: I'm looking for a function that can tell me what week in the month a given data date is from.</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/I-m-looking-for-a-function-that-can-tell-me-what-week-in-the/m-p/407371#M12422</link>
      <description>&lt;P&gt;Since "Week" is a somewhat slippery topic you need to define exactly all of your rules. You might notice that SAS supplies three different options to the Week function, U, V and W&amp;nbsp;to extract week of year information from dates depending on some common rules.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So how do you determine which week of a month a value may be in?&lt;/P&gt;
&lt;P&gt;And when you say "4 weeks" are you making the common mistaken assumption that a month consists of 4 weeks? Since there are 52.143 (approximatel) weeks in&amp;nbsp;most years, then on average (not always useful) there are 4.35 weeks in a month. Or 30/7=4.29 and 31/7=4.43 weeks in given months. Then of course there is Leap Year behavior to consider.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2017 17:11:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/I-m-looking-for-a-function-that-can-tell-me-what-week-in-the/m-p/407371#M12422</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-10-25T17:11:38Z</dc:date>
    </item>
  </channel>
</rss>

