<?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: How to use macro in datetime constant syntax? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-in-datetime-constant-syntax/m-p/559149#M156108</link>
    <description>&lt;P&gt;You need to enclose macro variables in double-quotes if you are going to use a macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date=01APR2019;

data _null_;
     a="&amp;amp;date 00:00:00.000"dt;
     call symput('dtime',a);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please note proper terminology for clarity: this is not a macro as your question implies, this is a macro variable, which is different.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Even easier:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dtime=%sysfunc(dhms("&amp;amp;date"d,0,0,0));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 15 May 2019 20:17:35 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2019-05-15T20:17:35Z</dc:date>
    <item>
      <title>How to use macro in datetime constant syntax?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-in-datetime-constant-syntax/m-p/559148#M156107</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a large dataset, from which I want to extract a subset based on a datetime variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far, I've managed to obtain the SAS datetime that I want as a macro variable. For instance, I want the SAS datetime for 2019-04-01, 00:00:00:000, and I've tried the following to save the datetime as a macro variable called "dtime":&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;STRONG&gt;data save;&lt;/STRONG&gt;
a=&lt;FONT color="#008080"&gt;'01APR2019, 00:00:00.000'dt&lt;/FONT&gt;;
&lt;STRONG&gt;run;&lt;/STRONG&gt;

&lt;STRONG&gt;data&lt;/STRONG&gt; &lt;FONT color="#3366FF"&gt;_null_&lt;/FONT&gt;;
&lt;FONT color="#3366FF"&gt;set&lt;/FONT&gt; save;
&lt;FONT color="#3366FF"&gt;call&lt;/FONT&gt; symput(&lt;FONT color="#800080"&gt;"dtime"&lt;/FONT&gt;, a);
&lt;STRONG&gt;run;&lt;/STRONG&gt;&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;&lt;STRONG&gt;Question:&lt;/STRONG&gt; Because I will have to repeat the codes above many times to subset based on multiple different dates, I am wondering if I can &lt;U&gt;create a macro for the date part of the datetime&lt;/U&gt;. I tried the following to add a macro variable called "date" that has the date of interest:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;STRONG&gt;%let&lt;/STRONG&gt; date=01APR2019;

&lt;STRONG&gt;data&lt;/STRONG&gt; save;
a=&lt;FONT color="#008080"&gt;'&amp;amp;date, 00:00:00.000'dt&lt;/FONT&gt;;
&lt;STRONG&gt;run;&lt;/STRONG&gt;

&lt;STRONG&gt;data&lt;/STRONG&gt; &lt;FONT color="#3366FF"&gt;_null_&lt;/FONT&gt;;
&lt;FONT color="#3366FF"&gt;set&lt;/FONT&gt; save;
&lt;FONT color="#3366FF"&gt;call&lt;/FONT&gt; symput("dtime", a);
&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Nonetheless, the &amp;amp;date part is not evaluated in the data step. So I wonder if there's way to let a = &lt;FONT color="#008080"&gt;'01APR2019, 00:00:00.000'dt&lt;/FONT&gt; in the data step with the help of this macro variable "date".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First time posting, so I apologize if my question was not clearly stated.&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2019 20:09:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-in-datetime-constant-syntax/m-p/559148#M156107</guid>
      <dc:creator>aaronh</dc:creator>
      <dc:date>2019-05-15T20:09:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro in datetime constant syntax?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-in-datetime-constant-syntax/m-p/559149#M156108</link>
      <description>&lt;P&gt;You need to enclose macro variables in double-quotes if you are going to use a macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date=01APR2019;

data _null_;
     a="&amp;amp;date 00:00:00.000"dt;
     call symput('dtime',a);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please note proper terminology for clarity: this is not a macro as your question implies, this is a macro variable, which is different.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Even easier:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dtime=%sysfunc(dhms("&amp;amp;date"d,0,0,0));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2019 20:17:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-in-datetime-constant-syntax/m-p/559149#M156108</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-05-15T20:17:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro in datetime constant syntax?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-in-datetime-constant-syntax/m-p/559150#M156109</link>
      <description>&lt;P&gt;Thank you so much! I didn't realize there is a short-cut (albeit a somewhat more complex one) that gets me the same result. Thanks for helping me out!&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2019 20:24:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-in-datetime-constant-syntax/m-p/559150#M156109</guid>
      <dc:creator>aaronh</dc:creator>
      <dc:date>2019-05-15T20:24:08Z</dc:date>
    </item>
  </channel>
</rss>

