<?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: Within a Macro - create a dynamic macro variable for the current time in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Within-a-Macro-create-a-dynamic-macro-variable-for-the-current/m-p/611021#M178030</link>
    <description>&lt;P&gt;You seem a little confused about what the macro processor does and when it does it.&amp;nbsp; It modifies the code and passes on to SAS to execute.&amp;nbsp; So your %PUT statements in the middle of a data step will execute BEFORE the data step executes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could either use macro code to make your macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let C_Time=%sysfunc(time(),timeampm.);
%put The current time is &amp;amp;=C_Time;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or use SAS code to make the macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  now=time();
  put 'The Non-macro time is ' now timeampm.;
  call symputx('C_Time',put(now,timeampm.));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you did want to use the value of the macro variable to generate some SAS code them make sure it is generating valid SAS code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  put "The value of C_TIME is &amp;amp;c_time".
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 11 Dec 2019 14:54:36 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-12-11T14:54:36Z</dc:date>
    <item>
      <title>Within a Macro - create a dynamic macro variable for the current time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Within-a-Macro-create-a-dynamic-macro-variable-for-the-current/m-p/610958#M178024</link>
      <description>&lt;P&gt;Seems simple enough –&amp;nbsp; An hour later and various attempts, no further forward, so bow to the experts:-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data _Null_;
     call symputx('C_Time',%sysfunc(time(),timeampm.));
     %put The current time is &amp;amp;=C_Time;
     %put The Non-macro time is %sysfunc(time(),timeampm.);
Run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Excerpt from the Log&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;33       !  Data _Null_;
34                   call symputx('C_Time',%sysfunc(time(),timeampm.));
NOTE: Line generated by the macro function "SYSFUNC".
34         11:43:04 AM
             _
             388
             200
ERROR 388-185: Expecting an arithmetic operator.

ERROR 200-322: The symbol is not recognized and will be ignored.

35                   %put The current time is &amp;amp;=C_Time;
WARNING: Apparent symbolic reference C_TIME not resolved.
The current time is C_Time
36                   %put The Non-macro time is %sysfunc(time(),timeampm.);
The Non-macro time is 11:43:04 AM
37              Run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Even if I wrap the second argument with a Put to specifically convert Numeric to Character – same result.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What is the answer?&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2019 12:13:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Within-a-Macro-create-a-dynamic-macro-variable-for-the-current/m-p/610958#M178024</guid>
      <dc:creator>Brunts23</dc:creator>
      <dc:date>2019-12-11T12:13:06Z</dc:date>
    </item>
    <item>
      <title>Re: Within a Macro - create a dynamic macro variable for the current time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Within-a-Macro-create-a-dynamic-macro-variable-for-the-current/m-p/610960#M178026</link>
      <description>&lt;P&gt;The second argument to the call symput routine must be a string, so use double quotes.&lt;/P&gt;
&lt;P&gt;And move the %put statements after the run, as they would otherwise be resolved before the data step runs, and throw an error.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data _Null_;
call symputx('C_Time',"%sysfunc(time(),timeampm.)");
Run;

%put The current time is &amp;amp;=C_Time;
%put The Non-macro time is %sysfunc(time(),timeampm.);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Dec 2019 12:22:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Within-a-Macro-create-a-dynamic-macro-variable-for-the-current/m-p/610960#M178026</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-12-11T12:22:47Z</dc:date>
    </item>
    <item>
      <title>Re: Within a Macro - create a dynamic macro variable for the current time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Within-a-Macro-create-a-dynamic-macro-variable-for-the-current/m-p/610966#M178029</link>
      <description>&lt;P&gt;If you are inside a macro, then using&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let C_Time = %sysfunc(time(),timeampm.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;should solve the problem. If you want to use a data step, replacing %sysfunc with&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; call symputx('C_Time', put(time(),timeampm.));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;should be all you need.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2019 12:46:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Within-a-Macro-create-a-dynamic-macro-variable-for-the-current/m-p/610966#M178029</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-12-11T12:46:54Z</dc:date>
    </item>
    <item>
      <title>Re: Within a Macro - create a dynamic macro variable for the current time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Within-a-Macro-create-a-dynamic-macro-variable-for-the-current/m-p/611021#M178030</link>
      <description>&lt;P&gt;You seem a little confused about what the macro processor does and when it does it.&amp;nbsp; It modifies the code and passes on to SAS to execute.&amp;nbsp; So your %PUT statements in the middle of a data step will execute BEFORE the data step executes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could either use macro code to make your macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let C_Time=%sysfunc(time(),timeampm.);
%put The current time is &amp;amp;=C_Time;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or use SAS code to make the macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  now=time();
  put 'The Non-macro time is ' now timeampm.;
  call symputx('C_Time',put(now,timeampm.));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you did want to use the value of the macro variable to generate some SAS code them make sure it is generating valid SAS code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  put "The value of C_TIME is &amp;amp;c_time".
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Dec 2019 14:54:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Within-a-Macro-create-a-dynamic-macro-variable-for-the-current/m-p/611021#M178030</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-12-11T14:54:36Z</dc:date>
    </item>
    <item>
      <title>Re: Within a Macro - create a dynamic macro variable for the current time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Within-a-Macro-create-a-dynamic-macro-variable-for-the-current/m-p/611030#M178034</link>
      <description>&lt;P&gt;I'm slowly completing the Advanced SAS training and trying to work things out in my head as to what works and why - Thanks for the input&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2019 14:59:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Within-a-Macro-create-a-dynamic-macro-variable-for-the-current/m-p/611030#M178034</guid>
      <dc:creator>Brunts23</dc:creator>
      <dc:date>2019-12-11T14:59:32Z</dc:date>
    </item>
  </channel>
</rss>

