<?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 SAS EG 5.1 Macro Variable for date validation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-EG-5-1-Macro-Variable-for-date-validation/m-p/363425#M274899</link>
    <description>&lt;P&gt;For the life of me I cannot remember how to do this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following %let statement(s), which work beautifully when setting them in my where statements:&lt;/P&gt;&lt;P&gt;*CURRENT DATE*/&lt;/P&gt;&lt;P&gt;%LET CD=INTNX('DAY',TODAY(),-1);&lt;/P&gt;&lt;P&gt;/*CURRENT MONTH START DATE*/&lt;/P&gt;&lt;P&gt;%LET CM=INTNX('MONTH',INTNX('MONTH',TODAY(),1),-1);&lt;/P&gt;&lt;P&gt;/*CURRENT YEAR START DATE*/&lt;/P&gt;&lt;P&gt;%LET CY=INTNX('YEAR',INTNX('YEAR',&amp;amp;CD,1),-1);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I cannot remember how in the world to validate the dates&amp;nbsp;(results shown in the log) with the %put statement.&amp;nbsp; Any one out there have any ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 01 Jun 2017 13:35:17 GMT</pubDate>
    <dc:creator>EIrvin</dc:creator>
    <dc:date>2017-06-01T13:35:17Z</dc:date>
    <item>
      <title>SAS EG 5.1 Macro Variable for date validation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-EG-5-1-Macro-Variable-for-date-validation/m-p/363425#M274899</link>
      <description>&lt;P&gt;For the life of me I cannot remember how to do this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following %let statement(s), which work beautifully when setting them in my where statements:&lt;/P&gt;&lt;P&gt;*CURRENT DATE*/&lt;/P&gt;&lt;P&gt;%LET CD=INTNX('DAY',TODAY(),-1);&lt;/P&gt;&lt;P&gt;/*CURRENT MONTH START DATE*/&lt;/P&gt;&lt;P&gt;%LET CM=INTNX('MONTH',INTNX('MONTH',TODAY(),1),-1);&lt;/P&gt;&lt;P&gt;/*CURRENT YEAR START DATE*/&lt;/P&gt;&lt;P&gt;%LET CY=INTNX('YEAR',INTNX('YEAR',&amp;amp;CD,1),-1);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I cannot remember how in the world to validate the dates&amp;nbsp;(results shown in the log) with the %put statement.&amp;nbsp; Any one out there have any ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jun 2017 13:35:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-EG-5-1-Macro-Variable-for-date-validation/m-p/363425#M274899</guid>
      <dc:creator>EIrvin</dc:creator>
      <dc:date>2017-06-01T13:35:17Z</dc:date>
    </item>
    <item>
      <title>Re: SAS EG 5.1 Macro Variable for date validation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-EG-5-1-Macro-Variable-for-date-validation/m-p/363431#M274900</link>
      <description>&lt;P&gt;Erm, thats obfuscation. &amp;nbsp;We have a function called today() which everyone knows, and you are wrapping that into macro variables, why? &amp;nbsp;You can just use the function directly in code, for example this:&lt;/P&gt;
&lt;PRE&gt;%LET CD=INTNX('DAY',TODAY(),-1);

data want;
  set have;
  where date=&amp;amp;cd.;
run;&lt;/PRE&gt;
&lt;P&gt;Is the same (but harder to debug) as:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  where date=today()-1;
run;&lt;/PRE&gt;
&lt;P&gt;As for putting that information into the log, you first need to actually run the code held in the macro varaibles, as they are just text, so maybe something like:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  format cd cm cy date9.;
  cd=&amp;amp;cd.;
  cm=&amp;amp;cm.;
  cy=&amp;amp;cy.;
  put _all_;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Jun 2017 13:47:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-EG-5-1-Macro-Variable-for-date-validation/m-p/363431#M274900</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-06-01T13:47:24Z</dc:date>
    </item>
    <item>
      <title>Re: SAS EG 5.1 Macro Variable for date validation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-EG-5-1-Macro-Variable-for-date-validation/m-p/363482#M274901</link>
      <description>&lt;P&gt;You are just assigning the CODE to calculate dates to the macro variables. You are not actually telling SAS to execute that code.&lt;/P&gt;
&lt;P&gt;If you want to execute functions in macro code then you need to use the %SYSFUNC() macro function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET CD=%sysfunc(INTNX(DAY,%sysfunc(TODAY()),-1));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This will set CD to the number of days since 01JAn1960. &amp;nbsp;That is fine for using in SAS code, but would be diffucult for a human to translate. &amp;nbsp;You could use the option second argument to %SYSFUNC() to have SAS format the result to look like a date.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET CD=%sysfunc(INTNX(DAY,%sysfunc(TODAY()),-1),date9);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But then to use it in SAS code you will need to let SAS itself know that you meant that stream of characters to represent a date. &amp;nbsp;For example by using it as a date literal.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;duration = "&amp;amp;cd"d - start_dt ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Jun 2017 15:12:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-EG-5-1-Macro-Variable-for-date-validation/m-p/363482#M274901</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-06-01T15:12:21Z</dc:date>
    </item>
  </channel>
</rss>

