<?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 Macro Variable Format to Use in a Datastep in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Date-Macro-Variable-Format-to-Use-in-a-Datastep/m-p/366900#M87312</link>
    <description>&lt;P&gt;You do not need macro for this, one SQL step can do it all:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WANT as
  select  *
  from    (select max(DATE) from OTHERDATASET) &amp;lt;= DATE &amp;lt;= "20MAY2006"d;
quit;&lt;/PRE&gt;
&lt;P&gt;Note that you have not provided any test data (in the form of a dataset) for us to work with, so this is all guesswork. &amp;nbsp;Also your where clause second part will not work, "20MAY06" is not a valid date valid, not even if you put a d after it for date literal.&lt;/P&gt;
&lt;P&gt;Finally, dates are numeric, it should not matter if the macro resolves to 10856 or something, as that should still be comparable to the DATE variable if its numeric. &amp;nbsp;If you post your full question, providing sample test data in the form of a datastep and what the output should look like then we can tailor the code to your needs.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 14 Jun 2017 10:41:44 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-06-14T10:41:44Z</dc:date>
    <item>
      <title>Date Macro Variable Format to Use in a Datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-Macro-Variable-Format-to-Use-in-a-Datastep/m-p/366894#M87309</link>
      <description>&lt;P&gt;I have seen similar questions in the forums and tried various things, but am not getting any result.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I'm trying to achieve:&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to get the maximum date from a dataset and then use this date to retrieve a subset from an existing dataset. I've used Proc SQL to get the maximum date and stored this as a macro variable. The trouble is that it is no longer in DATE. format. So when I try to use my variable in the datastep I get an error about non-compatible variables.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My current code where the error occurs:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SET testdata;&lt;/P&gt;&lt;P&gt;WHERE (&amp;amp;MD - 364) &amp;lt;= DATE &amp;lt;= '20MAY06';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Other notes:&lt;/P&gt;&lt;P&gt;&amp;amp;MD is the maximum date, when I format&amp;nbsp;as FORMAT &amp;amp;MD DATE.; it works fine. However it does not stay that way for my WHERE clause. The date cannot be hard-coded.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2017 10:04:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-Macro-Variable-Format-to-Use-in-a-Datastep/m-p/366894#M87309</guid>
      <dc:creator>buffalol</dc:creator>
      <dc:date>2017-06-14T10:04:17Z</dc:date>
    </item>
    <item>
      <title>Re: Date Macro Variable Format to Use in a Datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-Macro-Variable-Format-to-Use-in-a-Datastep/m-p/366900#M87312</link>
      <description>&lt;P&gt;You do not need macro for this, one SQL step can do it all:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WANT as
  select  *
  from    (select max(DATE) from OTHERDATASET) &amp;lt;= DATE &amp;lt;= "20MAY2006"d;
quit;&lt;/PRE&gt;
&lt;P&gt;Note that you have not provided any test data (in the form of a dataset) for us to work with, so this is all guesswork. &amp;nbsp;Also your where clause second part will not work, "20MAY06" is not a valid date valid, not even if you put a d after it for date literal.&lt;/P&gt;
&lt;P&gt;Finally, dates are numeric, it should not matter if the macro resolves to 10856 or something, as that should still be comparable to the DATE variable if its numeric. &amp;nbsp;If you post your full question, providing sample test data in the form of a datastep and what the output should look like then we can tailor the code to your needs.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2017 10:41:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-Macro-Variable-Format-to-Use-in-a-Datastep/m-p/366900#M87312</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-06-14T10:41:44Z</dc:date>
    </item>
    <item>
      <title>Re: Date Macro Variable Format to Use in a Datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-Macro-Variable-Format-to-Use-in-a-Datastep/m-p/366905#M87315</link>
      <description>&lt;P&gt;I am currently doing training and one of the questions asks for the maximum date to be called MD. I assume for use in later exercises. Essentially I am asking how to convert a macro variable to DATE.(which displays as 10FEB01 in columns) format and how to use it in one or more datasteps later. I need to minus 364 days from the Maxdate and then subset an existing dataset using a known date and the maxdate retrieved earlier.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So (Maxdate - 364) up to knowndate.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried using your code but it did not work. Got a syntax error on the the comparison operator &amp;gt;=&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2017 11:15:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-Macro-Variable-Format-to-Use-in-a-Datastep/m-p/366905#M87315</guid>
      <dc:creator>buffalol</dc:creator>
      <dc:date>2017-06-14T11:15:04Z</dc:date>
    </item>
    <item>
      <title>Re: Date Macro Variable Format to Use in a Datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-Macro-Variable-Format-to-Use-in-a-Datastep/m-p/366908#M87317</link>
      <description>&lt;P&gt;Most likely, the error has nothing to do with &amp;amp;MD. &amp;nbsp;As far as SAS is concerned, &amp;amp;MD can remain unformatted, and still be part of a valid date comparison.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The problem lies on the other side of the comparison. &amp;nbsp;'20MAY06' is a character string, not a date. &amp;nbsp;I doubt that the date you are comparing it to is a character string (but if it is that opens up a larger set of issues). &amp;nbsp;Instead of using '20MAY06' change that to '20MAY2006'd&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2017 11:25:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-Macro-Variable-Format-to-Use-in-a-Datastep/m-p/366908#M87317</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-06-14T11:25:38Z</dc:date>
    </item>
    <item>
      <title>Re: Date Macro Variable Format to Use in a Datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-Macro-Variable-Format-to-Use-in-a-Datastep/m-p/366909#M87318</link>
      <description>&lt;P&gt;That was exactly it. All this time and that was the only thing I had to change. I'm not sure whether to feel happy or sad at this point. Thank you.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2017 11:30:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-Macro-Variable-Format-to-Use-in-a-Datastep/m-p/366909#M87318</guid>
      <dc:creator>buffalol</dc:creator>
      <dc:date>2017-06-14T11:30:32Z</dc:date>
    </item>
    <item>
      <title>Re: Date Macro Variable Format to Use in a Datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-Macro-Variable-Format-to-Use-in-a-Datastep/m-p/366911#M87320</link>
      <description>&lt;P&gt;See my Maxim 28. For use in comparisons or value assignments, macro variables do not need to have formatted values; it is usually better to keep the raw values, as you can simply use &amp;amp;macrovar instead of "&amp;amp;macrovar"d (in case of dates).&lt;/P&gt;
&lt;P&gt;So stay with the way you used &amp;amp;MD.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2017 11:38:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-Macro-Variable-Format-to-Use-in-a-Datastep/m-p/366911#M87320</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-06-14T11:38:52Z</dc:date>
    </item>
  </channel>
</rss>

