<?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: Date reference that always takes date of most recent Sunday? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Date-reference-that-always-takes-date-of-most-recent-Sunday/m-p/854407#M337666</link>
    <description>&lt;P&gt;Setting a macro variable to a string that is that function call:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET previous_sunday = intnx('week',today(),0,'b');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Means you can use it any place where SAS would allow the same function call.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
 set have;
  myvar = &amp;amp;previous_sunday;
  format myvar date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since when the macro variable is expanded you will still have valid SAS code for SAS to run.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
 set have;
  myvar = intnx('week',today(),0,'b');
  format myvar date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But if you try to use that in some string, like a TITLE:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;TITLE "Last Sunday is &amp;amp;previous_sunday";
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you also just get the same text, and not the value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;TITLE "Last Sunday is intnx('week',today(),0,'b')";&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 18 Jan 2023 19:06:20 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-01-18T19:06:20Z</dc:date>
    <item>
      <title>Date reference that always takes date of most recent Sunday?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-reference-that-always-takes-date-of-most-recent-Sunday/m-p/854391#M337656</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a recurring reference in my code that I'd like to automate so that I don't need to update it manually.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%LET current_week ='15Jan2023'd; /* should be last Sunday */&lt;/PRE&gt;
&lt;P&gt;Here is the global reference as of this week, but it has a pattern. It's always going to be the last Sunday. Is there logic that can input this for me automatically? I was thinking a mix of today() and intx(), but I am coming up short.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your help.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jan 2023 17:45:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-reference-that-always-takes-date-of-most-recent-Sunday/m-p/854391#M337656</guid>
      <dc:creator>illmatic</dc:creator>
      <dc:date>2023-01-18T17:45:22Z</dc:date>
    </item>
    <item>
      <title>Re: Date reference that always takes date of most recent Sunday?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-reference-that-always-takes-date-of-most-recent-Sunday/m-p/854393#M337657</link>
      <description>&lt;P&gt;I find your explanation to be very unclear. Could you please clarify and give a clear example (or two)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The date you show, 15JAN2023 is a Sunday. Are the dates always on a Sunday? Do you want the the date of the previous Sunday? That's not the same as "date of most recent Sunday". Or is it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can the date ever be a Wednesday and you want the most recent Sunday? In this case&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
    day_to_use=today(); /* I wrote this code on 18JAN2023, a Wednesday */
    previous_sunday=intnx('week',day_to_use,0,'b');
    format previous_sunday day_to_use date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jan 2023 17:55:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-reference-that-always-takes-date-of-most-recent-Sunday/m-p/854393#M337657</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-01-18T17:55:54Z</dc:date>
    </item>
    <item>
      <title>Re: Date reference that always takes date of most recent Sunday?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-reference-that-always-takes-date-of-most-recent-Sunday/m-p/854404#M337663</link>
      <description>Hi Paige! My apologies, I wrote this too quickly.&lt;BR /&gt;&lt;BR /&gt;So the date will always be the previous Sunday.&lt;BR /&gt;&lt;BR /&gt;Example 1: Run the code today (Wednesday), result = 1/15/2023 (prior Sunday)&lt;BR /&gt;Example 2: Run the code on Monday (1/23/2023) next week, result = 1/22/2023 (prior Sunday)&lt;BR /&gt;&lt;BR /&gt;I believe your code works in a global reference method.&lt;BR /&gt;%LET previous_sunday = intnx('week',today(),0,'b');&lt;BR /&gt;&lt;BR /&gt;thank you very much for your help!</description>
      <pubDate>Wed, 18 Jan 2023 18:56:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-reference-that-always-takes-date-of-most-recent-Sunday/m-p/854404#M337663</guid>
      <dc:creator>illmatic</dc:creator>
      <dc:date>2023-01-18T18:56:24Z</dc:date>
    </item>
    <item>
      <title>Re: Date reference that always takes date of most recent Sunday?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-reference-that-always-takes-date-of-most-recent-Sunday/m-p/854407#M337666</link>
      <description>&lt;P&gt;Setting a macro variable to a string that is that function call:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET previous_sunday = intnx('week',today(),0,'b');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Means you can use it any place where SAS would allow the same function call.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
 set have;
  myvar = &amp;amp;previous_sunday;
  format myvar date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since when the macro variable is expanded you will still have valid SAS code for SAS to run.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
 set have;
  myvar = intnx('week',today(),0,'b');
  format myvar date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But if you try to use that in some string, like a TITLE:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;TITLE "Last Sunday is &amp;amp;previous_sunday";
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you also just get the same text, and not the value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;TITLE "Last Sunday is intnx('week',today(),0,'b')";&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Jan 2023 19:06:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-reference-that-always-takes-date-of-most-recent-Sunday/m-p/854407#M337666</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-01-18T19:06:20Z</dc:date>
    </item>
    <item>
      <title>Re: Date reference that always takes date of most recent Sunday?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-reference-that-always-takes-date-of-most-recent-Sunday/m-p/854419#M337672</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/434901"&gt;@illmatic&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hi Paige! My apologies, I wrote this too quickly.&lt;BR /&gt;&lt;BR /&gt;So the date will always be the previous Sunday.&lt;BR /&gt;&lt;BR /&gt;Example 1: Run the code today (Wednesday), result = 1/15/2023 (prior Sunday)&lt;BR /&gt;Example 2: Run the code on Monday (1/23/2023) next week, result = 1/22/2023 (prior Sunday)&lt;BR /&gt;&lt;BR /&gt;I believe your code works in a global reference method.&lt;BR /&gt;%LET previous_sunday = intnx('week',today(),0,'b');&lt;BR /&gt;&lt;BR /&gt;thank you very much for your help!&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What should happen if the code is run on a Sunday, let's say 22JAN2023. What is the desired output? Or is it never the case that the code is run on a Sunday?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why are you using macro variables here? What is it about the problem that macro variables are needed? How are you going to use this macro variable?&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jan 2023 19:28:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-reference-that-always-takes-date-of-most-recent-Sunday/m-p/854419#M337672</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-01-18T19:28:26Z</dc:date>
    </item>
    <item>
      <title>Re: Date reference that always takes date of most recent Sunday?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-reference-that-always-takes-date-of-most-recent-Sunday/m-p/854650#M337784</link>
      <description>Hi Paige!&lt;BR /&gt;&lt;BR /&gt;The code is scheduled to run on Mondays. The intention of the reference is to automate the output instead of having to enter the date each time.&lt;BR /&gt;The code captures transactions and rolls it up to weekly amounts with Sundays as the reference date.</description>
      <pubDate>Thu, 19 Jan 2023 18:35:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-reference-that-always-takes-date-of-most-recent-Sunday/m-p/854650#M337784</guid>
      <dc:creator>illmatic</dc:creator>
      <dc:date>2023-01-19T18:35:36Z</dc:date>
    </item>
    <item>
      <title>Re: Date reference that always takes date of most recent Sunday?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-reference-that-always-takes-date-of-most-recent-Sunday/m-p/854653#M337786</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/434901"&gt;@illmatic&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;BR /&gt;The code is scheduled to run on Mondays.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;May I recommend that from now on, important pieces of information be stated in the first message in your thread.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are running the code on Mondays, then the Sunday of interest is much more easily computed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;sunday_before = today()-1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;The intention of the reference is to automate the output instead of having to enter the date each time.&lt;BR /&gt;The code captures transactions and rolls it up to weekly amounts with Sundays as the reference date.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Based on what you have said, none of this requires macro variables. The only place would be if you are going to include the date in a folder or file name or title or label or footnote, for example, then you would need a macro variable. The code I have already provided doesn't use macro variables, and yet the value of the previous Sunday is properly computed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2023 18:52:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-reference-that-always-takes-date-of-most-recent-Sunday/m-p/854653#M337786</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-01-19T18:52:58Z</dc:date>
    </item>
  </channel>
</rss>

