<?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 Macros or Functions? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Date-Macros-or-Functions/m-p/485621#M126188</link>
    <description>&lt;P&gt;As long as you use actual date values you should have no need to involve macros for most things. And the macro language has no actual native date manipulation so you would be calling data step functions anyway.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The function today() should return the day&amp;nbsp; a program runs.&lt;/P&gt;
&lt;P&gt;You can test the data of the week with the WEEKDAY function with a date value. Weekday( today() ) returns 1 for Sunday, 2 for Monday … 7 for Saturday.&lt;/P&gt;
&lt;P&gt;So:&lt;/P&gt;
&lt;P&gt;If weekday(today()) = 2&amp;nbsp;then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;Monday code&amp;gt;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;else if weekday(today()) = 6 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;lt;Friday code&amp;gt;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The function INTNX can be used to set a date based on an existing date and an interval.&lt;/P&gt;
&lt;P&gt;otherdate = intnx('day', today(), 2) ; for example would set a value of 2 days from today for the SAS date value corresponding to 11Aug2018 when run on 09Aug2018.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code sort of implies that you may be entering values such as 20180809 manually. Those are NOT date values as far as SAS is concerned. A literal date value would be entered in SAS using '09AUG2018'd. If you are comparing the results of the TODAY() function to variables that look like 20180809 then some work will need to be done. You would have to tell us whether your dates are numeric or character and if they always appear as that OR if they actually are SAS date valued variables and have a YYMMDDN8. format applied.&lt;/P&gt;</description>
    <pubDate>Thu, 09 Aug 2018 23:01:51 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2018-08-09T23:01:51Z</dc:date>
    <item>
      <title>Date Macros or Functions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-Macros-or-Functions/m-p/485614#M126184</link>
      <description>&lt;P&gt;I'm Tasked to automate SAS programs on a windows task scheduler.Please note I'm a very new SAS developer.I have been reading about changing dates in program automatically&lt;/P&gt;&lt;P&gt;There are dates on these few SAS program, which we change manually everyday and run it.&lt;/P&gt;&lt;P&gt;Here are the situation of dates in the program:&lt;/P&gt;&lt;P&gt;1. Date= Today's Date. But if it is a Friday,Include dates between today(friday) and Sunday.&lt;/P&gt;&lt;P&gt;Where Date_received=20180809(today)&lt;/P&gt;&lt;P&gt;Where Date_received between&amp;nbsp;&lt;SPAN&gt;20180810 and&amp;nbsp;20180812&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. Date=Previous Date. But if it is Monday, Change date to Friday Date.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Where Date_received=20180807&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If the program run on Monday, then ,&amp;nbsp; Where Date_received=20180810&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3.Date=Last Sunday through&amp;nbsp;Saturday&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If the program run on&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;Monday(say August 13), then ,&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;Where Date_received&amp;nbsp;&amp;gt;&lt;/SPAN&gt;&lt;SPAN&gt;201808&lt;/SPAN&gt;&lt;SPAN&gt;05 and &lt;SPAN&gt;Date_received &amp;lt;20180811&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been reading about MACROS and SAS functions.&lt;/P&gt;&lt;P&gt;Please help me figure out , if it is better with Macros or date functions.&lt;/P&gt;&lt;P&gt;Also, if possible, point to articles to write ( or better help me write) the Macros for these date functions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hopefully it is the right forum im posting into..(&amp;nbsp;Base SAS programming forum).&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Thanks&lt;/P&gt;&lt;P&gt;SHree&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Aug 2018 22:04:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-Macros-or-Functions/m-p/485614#M126184</guid>
      <dc:creator>SaraDob</dc:creator>
      <dc:date>2018-08-09T22:04:39Z</dc:date>
    </item>
    <item>
      <title>Re: Date Macros or Functions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-Macros-or-Functions/m-p/485621#M126188</link>
      <description>&lt;P&gt;As long as you use actual date values you should have no need to involve macros for most things. And the macro language has no actual native date manipulation so you would be calling data step functions anyway.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The function today() should return the day&amp;nbsp; a program runs.&lt;/P&gt;
&lt;P&gt;You can test the data of the week with the WEEKDAY function with a date value. Weekday( today() ) returns 1 for Sunday, 2 for Monday … 7 for Saturday.&lt;/P&gt;
&lt;P&gt;So:&lt;/P&gt;
&lt;P&gt;If weekday(today()) = 2&amp;nbsp;then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;Monday code&amp;gt;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;else if weekday(today()) = 6 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;lt;Friday code&amp;gt;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The function INTNX can be used to set a date based on an existing date and an interval.&lt;/P&gt;
&lt;P&gt;otherdate = intnx('day', today(), 2) ; for example would set a value of 2 days from today for the SAS date value corresponding to 11Aug2018 when run on 09Aug2018.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code sort of implies that you may be entering values such as 20180809 manually. Those are NOT date values as far as SAS is concerned. A literal date value would be entered in SAS using '09AUG2018'd. If you are comparing the results of the TODAY() function to variables that look like 20180809 then some work will need to be done. You would have to tell us whether your dates are numeric or character and if they always appear as that OR if they actually are SAS date valued variables and have a YYMMDDN8. format applied.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Aug 2018 23:01:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-Macros-or-Functions/m-p/485621#M126188</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-08-09T23:01:51Z</dc:date>
    </item>
  </channel>
</rss>

