<?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: Selecting a Date range in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Selecting-a-Date-range/m-p/11266#M1277</link>
    <description>You could maybe do&lt;BR /&gt;
&lt;BR /&gt;
end=today()-weekday(today())+1;&lt;BR /&gt;
start=end-6;&lt;BR /&gt;
&lt;BR /&gt;
Good luck!</description>
    <pubDate>Mon, 04 Oct 2010 20:09:22 GMT</pubDate>
    <dc:creator>RickM</dc:creator>
    <dc:date>2010-10-04T20:09:22Z</dc:date>
    <item>
      <title>Selecting a Date range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Selecting-a-Date-range/m-p/11265#M1276</link>
      <description>I run a weekly report in &lt;B&gt;SAS 9.1&lt;/B&gt; that tracks data from the previous Monday to the current Sunday. For example, if I ran it today, the ranges would be: 9/27/10 to 10/3/10.&lt;BR /&gt;
&lt;BR /&gt;
I am trying to figure out a way to have these dates generate automatically. I can not figure out how to get the Monday thru Sunday date range. The trouble is sometimes the Monday will be from the previous month, and the Sunday date will be in the current month (like the above date sample).&lt;BR /&gt;
&lt;BR /&gt;
Is there a way within the intnx function that I can have the Monday date be generated every week? The closest I can get is: &lt;BR /&gt;
sdate=intnx('weekday','01sep2010'd,-2) &lt;BR /&gt;
&lt;BR /&gt;
That's fine for september, but not if I want the report to run automatically every month.</description>
      <pubDate>Mon, 04 Oct 2010 18:51:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Selecting-a-Date-range/m-p/11265#M1276</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-10-04T18:51:57Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting a Date range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Selecting-a-Date-range/m-p/11266#M1277</link>
      <description>You could maybe do&lt;BR /&gt;
&lt;BR /&gt;
end=today()-weekday(today())+1;&lt;BR /&gt;
start=end-6;&lt;BR /&gt;
&lt;BR /&gt;
Good luck!</description>
      <pubDate>Mon, 04 Oct 2010 20:09:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Selecting-a-Date-range/m-p/11266#M1277</guid>
      <dc:creator>RickM</dc:creator>
      <dc:date>2010-10-04T20:09:22Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting a Date range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Selecting-a-Date-range/m-p/11267#M1278</link>
      <description>&amp;gt; You could maybe do&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; end=today()-weekday(today())+1;&lt;BR /&gt;
&amp;gt; start=end-6;&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Good luck!&lt;BR /&gt;
&lt;BR /&gt;
That worked nicely. But...&lt;BR /&gt;
&lt;BR /&gt;
If I use what you suggested next Monday, will I get 10/4/10 for Monday and 10/11/10 for Sunday's date?</description>
      <pubDate>Mon, 04 Oct 2010 20:28:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Selecting-a-Date-range/m-p/11267#M1278</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-10-04T20:28:11Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting a Date range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Selecting-a-Date-range/m-p/11268#M1279</link>
      <description>Hi:&lt;BR /&gt;
  I suppose there's a more elegant way to do this with INTNX and shift intervals, but at least I can explain this logic.&lt;BR /&gt;
   Using INTNX with the WEEK interval and 'BEGIN' and an increment of 0&lt;BR /&gt;
[pre]&lt;BR /&gt;
intnx('week', date, 0, 'begin');&lt;BR /&gt;
[/pre]&lt;BR /&gt;
           &lt;BR /&gt;
will always take you to a SUNDAY. The trick is that on SUNDAY, you want the MONDAY from the previous week and on MON-SAT, you want the monday from the current week. The program below, I think, does what you want. As I said, there probably is a more elegant way to do it with INTNX. But as you can see from the output in the log, when the date used with INTNX is Oct 1, then the Monday created by this logic is Sept 27. &lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]7942  data testit;&lt;BR /&gt;
7943  do date='15sep2010'd to '15oct2010'd;&lt;BR /&gt;
7944     ** intnx of 'week' with 'begin' always goes to SUNDAY;&lt;BR /&gt;
7945     wdate=intnx('week', date, 0, 'begin');&lt;BR /&gt;
7946&lt;BR /&gt;
7947     ** so the wdate + 1 is going to be MONDAY if the day of week is Monday-Saturday;&lt;BR /&gt;
7948     ** when the day of week is SUNDAY, then you want the PREVIOUS Monday.;&lt;BR /&gt;
7949     day_of_week = weekday(date);&lt;BR /&gt;
7950     if day_of_week =1 then monday = wdate-6;&lt;BR /&gt;
7951     else monday = wdate +1;&lt;BR /&gt;
7952     putlog date= weekdate28. day_of_week=  wdate= weekdate28. monday= weekdate28. ;&lt;BR /&gt;
7953     if day_of_week = 1 then putlog ' ';&lt;BR /&gt;
7954  end;&lt;BR /&gt;
7955  run;&lt;BR /&gt;
&lt;BR /&gt;
date=Wednesday, Sep 15, 2010 day_of_week=4 wdate=Sunday, Sep 12, 2010 monday=Monday, Sep 13, 2010&lt;BR /&gt;
date=Thursday, Sep 16, 2010 day_of_week=5 wdate=Sunday, Sep 12, 2010 monday=Monday, Sep 13, 2010&lt;BR /&gt;
date=Friday, Sep 17, 2010 day_of_week=6 wdate=Sunday, Sep 12, 2010 monday=Monday, Sep 13, 2010&lt;BR /&gt;
date=Saturday, Sep 18, 2010 day_of_week=7 wdate=Sunday, Sep 12, 2010 monday=Monday, Sep 13, 2010&lt;BR /&gt;
date=Sunday, Sep 19, 2010 day_of_week=1 wdate=Sunday, Sep 19, 2010 monday=Monday, Sep 13, 2010&lt;BR /&gt;
                             &lt;BR /&gt;
date=Monday, Sep 20, 2010 day_of_week=2 wdate=Sunday, Sep 19, 2010 monday=Monday, Sep 20, 2010&lt;BR /&gt;
date=Tuesday, Sep 21, 2010 day_of_week=3 wdate=Sunday, Sep 19, 2010 monday=Monday, Sep 20, 2010&lt;BR /&gt;
date=Wednesday, Sep 22, 2010 day_of_week=4 wdate=Sunday, Sep 19, 2010 monday=Monday, Sep 20, 2010&lt;BR /&gt;
date=Thursday, Sep 23, 2010 day_of_week=5 wdate=Sunday, Sep 19, 2010 monday=Monday, Sep 20, 2010&lt;BR /&gt;
date=Friday, Sep 24, 2010 day_of_week=6 wdate=Sunday, Sep 19, 2010 monday=Monday, Sep 20, 2010&lt;BR /&gt;
date=Saturday, Sep 25, 2010 day_of_week=7 wdate=Sunday, Sep 19, 2010 monday=Monday, Sep 20, 2010&lt;BR /&gt;
date=Sunday, Sep 26, 2010 day_of_week=1 wdate=Sunday, Sep 26, 2010 monday=Monday, Sep 20, 2010&lt;BR /&gt;
                               &lt;BR /&gt;
date=Monday, Sep 27, 2010 day_of_week=2 wdate=Sunday, Sep 26, 2010 monday=Monday, Sep 27, 2010&lt;BR /&gt;
date=Tuesday, Sep 28, 2010 day_of_week=3 wdate=Sunday, Sep 26, 2010 monday=Monday, Sep 27, 2010&lt;BR /&gt;
date=Wednesday, Sep 29, 2010 day_of_week=4 wdate=Sunday, Sep 26, 2010 monday=Monday, Sep 27, 2010&lt;BR /&gt;
date=Thursday, Sep 30, 2010 day_of_week=5 wdate=Sunday, Sep 26, 2010 monday=Monday, Sep 27, 2010&lt;BR /&gt;
date=Friday, Oct 1, 2010 day_of_week=6 wdate=Sunday, Sep 26, 2010 monday=Monday, Sep 27, 2010&lt;BR /&gt;
date=Saturday, Oct 2, 2010 day_of_week=7 wdate=Sunday, Sep 26, 2010 monday=Monday, Sep 27, 2010&lt;BR /&gt;
date=Sunday, Oct 3, 2010 day_of_week=1 wdate=Sunday, Oct 3, 2010 monday=Monday, Sep 27, 2010&lt;BR /&gt;
                                  &lt;BR /&gt;
date=Monday, Oct 4, 2010 day_of_week=2 wdate=Sunday, Oct 3, 2010 monday=Monday, Oct 4, 2010&lt;BR /&gt;
date=Tuesday, Oct 5, 2010 day_of_week=3 wdate=Sunday, Oct 3, 2010 monday=Monday, Oct 4, 2010&lt;BR /&gt;
date=Wednesday, Oct 6, 2010 day_of_week=4 wdate=Sunday, Oct 3, 2010 monday=Monday, Oct 4, 2010&lt;BR /&gt;
date=Thursday, Oct 7, 2010 day_of_week=5 wdate=Sunday, Oct 3, 2010 monday=Monday, Oct 4, 2010&lt;BR /&gt;
date=Friday, Oct 8, 2010 day_of_week=6 wdate=Sunday, Oct 3, 2010 monday=Monday, Oct 4, 2010&lt;BR /&gt;
date=Saturday, Oct 9, 2010 day_of_week=7 wdate=Sunday, Oct 3, 2010 monday=Monday, Oct 4, 2010&lt;BR /&gt;
date=Sunday, Oct 10, 2010 day_of_week=1 wdate=Sunday, Oct 10, 2010 monday=Monday, Oct 4, 2010&lt;BR /&gt;
                         &lt;BR /&gt;
date=Monday, Oct 11, 2010 day_of_week=2 wdate=Sunday, Oct 10, 2010 monday=Monday, Oct 11, 2010&lt;BR /&gt;
date=Tuesday, Oct 12, 2010 day_of_week=3 wdate=Sunday, Oct 10, 2010 monday=Monday, Oct 11, 2010&lt;BR /&gt;
date=Wednesday, Oct 13, 2010 day_of_week=4 wdate=Sunday, Oct 10, 2010 monday=Monday, Oct 11, 2010&lt;BR /&gt;
date=Thursday, Oct 14, 2010 day_of_week=5 wdate=Sunday, Oct 10, 2010 monday=Monday, Oct 11, 2010&lt;BR /&gt;
date=Friday, Oct 15, 2010 day_of_week=6 wdate=Sunday, Oct 10, 2010 monday=Monday, Oct 11, 2010&lt;BR /&gt;
NOTE: The data set WORK.TESTIT has 1 observations and 4 variables.&lt;BR /&gt;
[/pre]</description>
      <pubDate>Mon, 04 Oct 2010 20:53:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Selecting-a-Date-range/m-p/11268#M1279</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-10-04T20:53:12Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting a Date range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Selecting-a-Date-range/m-p/11269#M1280</link>
      <description>cynthia&lt;BR /&gt;
&lt;BR /&gt;
Sorry for the delayed response. I have tested this and it worked. I'm going to apply it to my data and go from there. &lt;BR /&gt;
&lt;BR /&gt;
Thanks for the response.&lt;BR /&gt;
-Alana-</description>
      <pubDate>Fri, 15 Oct 2010 12:48:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Selecting-a-Date-range/m-p/11269#M1280</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-10-15T12:48:07Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting a Date range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Selecting-a-Date-range/m-p/11270#M1281</link>
      <description>I'm not sure I understand your use of previous and current, and the rest.  But you can use a shifted date interval to define a WEEK that starts on any day you like using WEEK.2 to create 1 week intervals that start on MONDAY.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
94   data _null_;&lt;BR /&gt;
95      file log ls=255;&lt;BR /&gt;
96      do date='15sep2010'd to '15oct2010'd;&lt;BR /&gt;
97         if weekday(date) eq 2 then put;&lt;BR /&gt;
98         sdate=intnx('week.2',date,0,'begin');&lt;BR /&gt;
99         edate=intnx('week.2',date,0,'end');&lt;BR /&gt;
100        putlog (date sdate edate)(+2 weekdate28.);&lt;BR /&gt;
101        end;&lt;BR /&gt;
102     run;&lt;BR /&gt;
&lt;BR /&gt;
       Wednesday, Sep 15, 2010          Monday, Sep 13, 2010          Sunday, Sep 19, 2010&lt;BR /&gt;
        Thursday, Sep 16, 2010          Monday, Sep 13, 2010          Sunday, Sep 19, 2010&lt;BR /&gt;
          Friday, Sep 17, 2010          Monday, Sep 13, 2010          Sunday, Sep 19, 2010&lt;BR /&gt;
        Saturday, Sep 18, 2010          Monday, Sep 13, 2010          Sunday, Sep 19, 2010&lt;BR /&gt;
          Sunday, Sep 19, 2010          Monday, Sep 13, 2010          Sunday, Sep 19, 2010&lt;BR /&gt;
&lt;BR /&gt;
          Monday, Sep 20, 2010          Monday, Sep 20, 2010          Sunday, Sep 26, 2010&lt;BR /&gt;
         Tuesday, Sep 21, 2010          Monday, Sep 20, 2010          Sunday, Sep 26, 2010&lt;BR /&gt;
       Wednesday, Sep 22, 2010          Monday, Sep 20, 2010          Sunday, Sep 26, 2010&lt;BR /&gt;
        Thursday, Sep 23, 2010          Monday, Sep 20, 2010          Sunday, Sep 26, 2010&lt;BR /&gt;
          Friday, Sep 24, 2010          Monday, Sep 20, 2010          Sunday, Sep 26, 2010&lt;BR /&gt;
        Saturday, Sep 25, 2010          Monday, Sep 20, 2010          Sunday, Sep 26, 2010&lt;BR /&gt;
          Sunday, Sep 26, 2010          Monday, Sep 20, 2010          Sunday, Sep 26, 2010&lt;BR /&gt;
&lt;BR /&gt;
          Monday, Sep 27, 2010          Monday, Sep 27, 2010           Sunday, Oct 3, 2010&lt;BR /&gt;
         Tuesday, Sep 28, 2010          Monday, Sep 27, 2010           Sunday, Oct 3, 2010&lt;BR /&gt;
       Wednesday, Sep 29, 2010          Monday, Sep 27, 2010           Sunday, Oct 3, 2010&lt;BR /&gt;
        Thursday, Sep 30, 2010          Monday, Sep 27, 2010           Sunday, Oct 3, 2010&lt;BR /&gt;
           Friday, Oct 1, 2010          Monday, Sep 27, 2010           Sunday, Oct 3, 2010&lt;BR /&gt;
         Saturday, Oct 2, 2010          Monday, Sep 27, 2010           Sunday, Oct 3, 2010&lt;BR /&gt;
           Sunday, Oct 3, 2010          Monday, Sep 27, 2010           Sunday, Oct 3, 2010&lt;BR /&gt;
&lt;BR /&gt;
           Monday, Oct 4, 2010           Monday, Oct 4, 2010          Sunday, Oct 10, 2010&lt;BR /&gt;
          Tuesday, Oct 5, 2010           Monday, Oct 4, 2010          Sunday, Oct 10, 2010&lt;BR /&gt;
        Wednesday, Oct 6, 2010           Monday, Oct 4, 2010          Sunday, Oct 10, 2010&lt;BR /&gt;
         Thursday, Oct 7, 2010           Monday, Oct 4, 2010          Sunday, Oct 10, 2010&lt;BR /&gt;
           Friday, Oct 8, 2010           Monday, Oct 4, 2010          Sunday, Oct 10, 2010&lt;BR /&gt;
         Saturday, Oct 9, 2010           Monday, Oct 4, 2010          Sunday, Oct 10, 2010&lt;BR /&gt;
          Sunday, Oct 10, 2010           Monday, Oct 4, 2010          Sunday, Oct 10, 2010&lt;BR /&gt;
&lt;BR /&gt;
          Monday, Oct 11, 2010          Monday, Oct 11, 2010          Sunday, Oct 17, 2010&lt;BR /&gt;
         Tuesday, Oct 12, 2010          Monday, Oct 11, 2010          Sunday, Oct 17, 2010&lt;BR /&gt;
       Wednesday, Oct 13, 2010          Monday, Oct 11, 2010          Sunday, Oct 17, 2010&lt;BR /&gt;
        Thursday, Oct 14, 2010          Monday, Oct 11, 2010          Sunday, Oct 17, 2010&lt;BR /&gt;
          Friday, Oct 15, 2010          Monday, Oct 11, 2010          Sunday, Oct 17, 2010&lt;BR /&gt;
[/pre]</description>
      <pubDate>Fri, 15 Oct 2010 13:49:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Selecting-a-Date-range/m-p/11270#M1281</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2010-10-15T13:49:36Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting a Date range</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Selecting-a-Date-range/m-p/11271#M1282</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;PROC SQL; &lt;BR /&gt;CREATE TABLE TEST AS&lt;BR /&gt;SELECT *&lt;BR /&gt;FROM&amp;nbsp; TABLENAME WHERE &lt;STRONG&gt;DATE BETWEEN (TODAY() - &lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt; AND (TODAY() -1);&lt;/STRONG&gt;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;DIV class="mcePaste" id="_mcePaste" style="left: -10000px; overflow: hidden; width: 1px; position: absolute; top: 0px; height: 1px;"&gt;﻿&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Feb 2012 20:44:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Selecting-a-Date-range/m-p/11271#M1282</guid>
      <dc:creator>Hima</dc:creator>
      <dc:date>2012-02-02T20:44:42Z</dc:date>
    </item>
  </channel>
</rss>

