<?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 Global date statements - SAS EG 5.1 in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Global-date-statements-SAS-EG-5-1/m-p/330238#M21937</link>
    <description>&lt;P&gt;Good Day all!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have hit a quandry that I am having some difficulty finding a workable solution outside of hard-coding dates.&amp;nbsp; I run a daily report where I compare Month-to-date to Prior Month-to-date and Prior Year Month-to-date. I have succesfully written out global statements to identif these ranges to where when the year rolls over there is no need to change any coding.&amp;nbsp; However, my quandry is looking at week-to-date and prior week-to-date.&amp;nbsp;&amp;nbsp;SAS identifies Sunday as the beginning of the week, however, my need is to run the week Monday- Sunday.&amp;nbsp; In addition to that caveat, I need a solution to keep the beginning of the week at Monday then compare this week to date to last week to date.&amp;nbsp; For example if today is Wednesday, Current Week-to-date should show the date ranges of this Monday to this Wednesday and the prior week-to-date to show last Monday through last Wednesday.&amp;nbsp; The dates that the program is pulling is based on dates that are preformatted ddmmmyyyy.&amp;nbsp; The global statements I have baked into my program work wonderfully and accurately, and they are shown below.&lt;/P&gt;&lt;PRE&gt;&lt;FONT size="1"&gt;&lt;FONT face="Courier New"&gt;&lt;CODE class=" language-sas"&gt;/*CURRENT DATE*/
%LET CD=INTNX('DAY',TODAY(),-1);
/*PREVIOUS YEAR START DATE*/
%LET PY=INTNX('YEAR',&amp;amp;CD,-1);
/*PREVIOUS YEAR MONTH START DATE*/
%LET PYM=INTNX('MONTH',&amp;amp;CD,-12);
/*PREVIOUS YEAR TO DATE*/
%LET PYTD=INTNX('YEAR',&amp;amp;CD,-1,'SAMEDAY');
/*CURRENT YEAR START DATE*/
%LET CY=INTNX('YEAR',INTNX('YEAR',&amp;amp;CD,1),-1);
/*PREVIOUS MONTH START DATE*/
%LET PM=INTNX('MONTH',&amp;amp;CD,-1);
/*PREVIOUS MONTH TO DATE*/
%LET PMTD=INTNX('MONTH',&amp;amp;CD,-1,'SAMEDAY');
/*CURRENT MONTH START DATE*/
%LET CM=INTNX('MONTH',INTNX('MONTH',&amp;amp;CD,1),-1);&lt;/CODE&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;P&gt;Any thoughts or suggestions would be greatly appreciated.&lt;/P&gt;</description>
    <pubDate>Mon, 06 Feb 2017 16:38:37 GMT</pubDate>
    <dc:creator>EIrvin</dc:creator>
    <dc:date>2017-02-06T16:38:37Z</dc:date>
    <item>
      <title>Global date statements - SAS EG 5.1</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Global-date-statements-SAS-EG-5-1/m-p/330238#M21937</link>
      <description>&lt;P&gt;Good Day all!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have hit a quandry that I am having some difficulty finding a workable solution outside of hard-coding dates.&amp;nbsp; I run a daily report where I compare Month-to-date to Prior Month-to-date and Prior Year Month-to-date. I have succesfully written out global statements to identif these ranges to where when the year rolls over there is no need to change any coding.&amp;nbsp; However, my quandry is looking at week-to-date and prior week-to-date.&amp;nbsp;&amp;nbsp;SAS identifies Sunday as the beginning of the week, however, my need is to run the week Monday- Sunday.&amp;nbsp; In addition to that caveat, I need a solution to keep the beginning of the week at Monday then compare this week to date to last week to date.&amp;nbsp; For example if today is Wednesday, Current Week-to-date should show the date ranges of this Monday to this Wednesday and the prior week-to-date to show last Monday through last Wednesday.&amp;nbsp; The dates that the program is pulling is based on dates that are preformatted ddmmmyyyy.&amp;nbsp; The global statements I have baked into my program work wonderfully and accurately, and they are shown below.&lt;/P&gt;&lt;PRE&gt;&lt;FONT size="1"&gt;&lt;FONT face="Courier New"&gt;&lt;CODE class=" language-sas"&gt;/*CURRENT DATE*/
%LET CD=INTNX('DAY',TODAY(),-1);
/*PREVIOUS YEAR START DATE*/
%LET PY=INTNX('YEAR',&amp;amp;CD,-1);
/*PREVIOUS YEAR MONTH START DATE*/
%LET PYM=INTNX('MONTH',&amp;amp;CD,-12);
/*PREVIOUS YEAR TO DATE*/
%LET PYTD=INTNX('YEAR',&amp;amp;CD,-1,'SAMEDAY');
/*CURRENT YEAR START DATE*/
%LET CY=INTNX('YEAR',INTNX('YEAR',&amp;amp;CD,1),-1);
/*PREVIOUS MONTH START DATE*/
%LET PM=INTNX('MONTH',&amp;amp;CD,-1);
/*PREVIOUS MONTH TO DATE*/
%LET PMTD=INTNX('MONTH',&amp;amp;CD,-1,'SAMEDAY');
/*CURRENT MONTH START DATE*/
%LET CM=INTNX('MONTH',INTNX('MONTH',&amp;amp;CD,1),-1);&lt;/CODE&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;P&gt;Any thoughts or suggestions would be greatly appreciated.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Feb 2017 16:38:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Global-date-statements-SAS-EG-5-1/m-p/330238#M21937</guid>
      <dc:creator>EIrvin</dc:creator>
      <dc:date>2017-02-06T16:38:37Z</dc:date>
    </item>
    <item>
      <title>Re: Global date statements - SAS EG 5.1</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Global-date-statements-SAS-EG-5-1/m-p/330242#M21938</link>
      <description>&lt;P&gt;It's difficult to confirm the accuracy of your current statements.&amp;nbsp; Macro language doesn't apply INTNX, for example, so there must be code somewhere in a DATA step (or perhaps within a SQL SELECT) that uses your macro variables, something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;d1 = &amp;amp;cd;&lt;/P&gt;
&lt;P&gt;d2 = &amp;amp;py;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since I can't see that code, I'll have to take your word for it that it is functioning well.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To approach your current problem, I would suggest the WEEKDAY function applied to the current date.&amp;nbsp; It can tell you enough to calculate the first day of the current week.&amp;nbsp; Then to get the previous week, subtract 7 from the beginning and end of the current week.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Feb 2017 17:03:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Global-date-statements-SAS-EG-5-1/m-p/330242#M21938</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-02-06T17:03:17Z</dc:date>
    </item>
    <item>
      <title>Re: Global date statements - SAS EG 5.1</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Global-date-statements-SAS-EG-5-1/m-p/330256#M21939</link>
      <description>&lt;P&gt;To do the same with WEEKS instead of months change your interval from 'MONTH' to 'WEEK' . To make the weeks start on Monday use 'WEEK.2'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*PREVIOUS WEEK START DATE*/ 
%LET PW=INTNX('WEEK.2',&amp;amp;CD,-1); 
/*PREVIOUS WEEK TO DATE*/ 
%LET PWTD=INTNX('WEEK.2',&amp;amp;CD,-1,'SAMEDAY'); 
/*CURRENT WEEK START DATE*/ 
%LET CW=INTNX('WEEK.2',&amp;amp;CD,0); 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also note that weeks are always 7 days long. So the PWTD can just be calculated directly from &amp;amp;CD.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET PWTD=&amp;amp;CD-7;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You do realize that your macro variables do not contain the actual dates. Instead they have the code that can be run to calculate the dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Feb 2017 18:52:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Global-date-statements-SAS-EG-5-1/m-p/330256#M21939</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-02-06T18:52:34Z</dc:date>
    </item>
    <item>
      <title>Re: Global date statements - SAS EG 5.1</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Global-date-statements-SAS-EG-5-1/m-p/330279#M21941</link>
      <description>&lt;P&gt;Thank you, this is what I needed, however, when I tried to run this in a copy of teh program, I received the following error, which I have not seen on my other %let statements, but where I placed the CW and PW codes caused all of the other %let statements to fail as well.&amp;nbsp;&amp;nbsp; Any idea on how to combat this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;16         /*CURRENT DATE*/
17         %LET CD=INTNX('DAY',TODAY(),-1);
18         /*CURRENT WEEK START DATE*/
19         %LET CW=INTNX('WEEK.2',&amp;amp;CD,0)
20         /*PRIOR WEEK START DATE*/
21         %LET PW=INTNX('WEEK.2',&amp;amp;CD,-1);
ERROR: Open code statement recursion detected.
22         /*PRIOR WEEK TO DATE*/
23         %LET PWTD=INTNX('WEEK.2',&amp;amp;CD,-1,'SAMEDAY')
ERROR: Open code statement recursion detected.
24         /*PREVIOUS YEAR START DATE*/
25         %LET PY=INTNX('YEAR',&amp;amp;CD,-1);
26         /*PREVIOUS YEAR MONTH START DATE*/
27         %LET PYM=INTNX('MONTH',&amp;amp;CD,-12);
ERROR: Open code statement recursion detected.
28         /*PREVIOUS YEAR TO DATE*/
29         %LET PYTD=INTNX('YEAR',&amp;amp;CD,-1,'SAMEDAY');
ERROR: Open code statement recursion detected.
30         /*CURRENT YEAR START DATE*/
31         %LET CY=INTNX('YEAR',INTNX('YEAR',&amp;amp;CD,1),-1);
ERROR: Open code statement recursion detected.
32         /*PREVIOUS MONTH START DATE*/
33         %LET PM=INTNX('MONTH',&amp;amp;CD,-1);
ERROR: Open code statement recursion detected.
34         /*PREVIOUS MONTH TO DATE*/
35         %LET PMTD=INTNX('MONTH',&amp;amp;CD,-1,'SAMEDAY');
ERROR: Open code statement recursion detected.
36         /*CURRENT MONTH START DATE*/
37         %LET CM=INTNX('MONTH',INTNX('MONTH',&amp;amp;CD,1),-1);
ERROR: Open code statement recursion detected.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Feb 2017 19:34:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Global-date-statements-SAS-EG-5-1/m-p/330279#M21941</guid>
      <dc:creator>EIrvin</dc:creator>
      <dc:date>2017-02-06T19:34:15Z</dc:date>
    </item>
    <item>
      <title>Re: Global date statements - SAS EG 5.1</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Global-date-statements-SAS-EG-5-1/m-p/330291#M21942</link>
      <description>&lt;P&gt;You're missing a semicolon at the end of line 19.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Feb 2017 19:57:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Global-date-statements-SAS-EG-5-1/m-p/330291#M21942</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2017-02-06T19:57:06Z</dc:date>
    </item>
  </channel>
</rss>

