<?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 logic error in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Date-logic-error/m-p/832002#M328848</link>
    <description>&lt;P&gt;Good point, format date9. would work but format mmddyy10. will not work, even after you fix the single-quotes should be double-quotes error.&lt;/P&gt;</description>
    <pubDate>Tue, 06 Sep 2022 18:12:33 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-09-06T18:12:33Z</dc:date>
    <item>
      <title>Date logic error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-logic-error/m-p/831998#M328844</link>
      <description>&lt;P&gt;Hi ..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I try to use the code below, I receive the error message listed below. Kindly help me with this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let date_cntrl = %sysfunc(intnx(day, %sysfunc(today()), -7), mmddyy10.);&lt;BR /&gt;%put &amp;amp;date_cntrl.;&lt;/P&gt;&lt;P&gt;data week;&lt;BR /&gt;set Stat_look;&lt;BR /&gt;where date &amp;lt;= '&amp;amp;date_cntrl.'d;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Getting an below error:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="cho16_0-1662487052791.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/75017i146AE871B2CBCF37/image-size/medium?v=v2&amp;amp;px=400" role="button" title="cho16_0-1662487052791.png" alt="cho16_0-1662487052791.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Sep 2022 17:59:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-logic-error/m-p/831998#M328844</guid>
      <dc:creator>cho16</dc:creator>
      <dc:date>2022-09-06T17:59:20Z</dc:date>
    </item>
    <item>
      <title>Re: Date logic error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-logic-error/m-p/832000#M328846</link>
      <description>&lt;P&gt;Use double quotes&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where date &amp;lt;= "&amp;amp;date_cntrl"d;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or even easier, use &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_self"&gt;Maxim 28&lt;/A&gt;, do not format macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date_cntrl = %sysfunc(intnx(day, %sysfunc(today()), -7));
%put &amp;amp;=date_cntrl;

data week;
    set Stat_look;
    where date &amp;lt;= &amp;amp;date_cntrl;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Sep 2022 18:09:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-logic-error/m-p/832000#M328846</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-06T18:09:44Z</dc:date>
    </item>
    <item>
      <title>Re: Date logic error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-logic-error/m-p/832001#M328847</link>
      <description>&lt;P&gt;Simple in this case. Two errors: First macro variables inside single quotes do not resolve. Use "&amp;nbsp; " when needed.&lt;/P&gt;
&lt;P&gt;After you fix that then the date value must be a DATE9 (or 7 or similar), i.e. 14JUL2022 format, not MMDDYY format that you applied.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yet another case of formatting a date when not needed. If you want the value to compare then don't format a macro variable. About the only valid reason to do so is when the value is used in something people read like Title text or the name of a file. If the only use of the variable is comparison as shown then don't format at all and just use the numeric value. If you are not using the macro variable a many different places it may be better to just use the Intnx function in the data step instead of a macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let date_cntrl = %sysfunc(intnx(day, %sysfunc(today()), -7));
%put &amp;amp;date_cntrl.;

data week;
set Stat_look;
where date &amp;lt;= &amp;amp;date_cntrl.
run;

 &lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Sep 2022 18:08:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-logic-error/m-p/832001#M328847</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-09-06T18:08:29Z</dc:date>
    </item>
    <item>
      <title>Re: Date logic error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-logic-error/m-p/832002#M328848</link>
      <description>&lt;P&gt;Good point, format date9. would work but format mmddyy10. will not work, even after you fix the single-quotes should be double-quotes error.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Sep 2022 18:12:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-logic-error/m-p/832002#M328848</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-06T18:12:33Z</dc:date>
    </item>
    <item>
      <title>Re: Date logic error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-logic-error/m-p/832021#M328849</link>
      <description>&lt;P&gt;Apart from using double quotes, you need the DATE9. format for date literals, not MMDDYY10.&lt;/P&gt;
&lt;P&gt;But it is much simpler to use unformatted values, as Maxim 28 says.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Sep 2022 18:32:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-logic-error/m-p/832021#M328849</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-09-06T18:32:11Z</dc:date>
    </item>
  </channel>
</rss>

