<?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 take hour and minutes of the current time into macro variables? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-take-hour-and-minutes-of-the-current-time-into-macro/m-p/597926#M172346</link>
    <description>&lt;P&gt;If you already have a macro variable with a string like:&lt;/P&gt;
&lt;PRE&gt;16:45&lt;/PRE&gt;
&lt;P&gt;Then just use %SCAN() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let hh=%scan(&amp;amp;time,1,:);
%let mm=%scan(&amp;amp;time,2,:);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What do you want for HH or MM when the value is less than 10?&amp;nbsp; Do you want 9 or 09?&lt;/P&gt;</description>
    <pubDate>Sat, 19 Oct 2019 21:00:57 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-10-19T21:00:57Z</dc:date>
    <item>
      <title>How to take hour and minutes of the current time into macro variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-take-hour-and-minutes-of-the-current-time-into-macro/m-p/597898#M172319</link>
      <description>&lt;P&gt;I would like to have hour (hh format) and minute (mm format) parts of the current time into two macro variables. I know how to take date and time (as below), but how can I take hour and minute parts from &amp;amp;time?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example 1) if time has 20:30, then I would like to have 20 for hh and 30 for mm.&lt;/P&gt;
&lt;P&gt;Example 2) if time has 7:30, then I would like to have 7 for hh and 30 for mm.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
	%let date=%sysfunc(today(), yymmdd6.);
	%let time=%sysfunc(time(), hhmm); %put &amp;amp;time;&lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 19 Oct 2019 16:33:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-take-hour-and-minutes-of-the-current-time-into-macro/m-p/597898#M172319</guid>
      <dc:creator>braam</dc:creator>
      <dc:date>2019-10-19T16:33:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to take hour and minutes of the current time into macro variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-take-hour-and-minutes-of-the-current-time-into-macro/m-p/597899#M172320</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   call symput('hh', hour(time()));
   call symput('mm', minute(time()));
run;

%put &amp;amp;hh.;
%put &amp;amp;mm.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 19 Oct 2019 16:40:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-take-hour-and-minutes-of-the-current-time-into-macro/m-p/597899#M172320</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-10-19T16:40:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to take hour and minutes of the current time into macro variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-take-hour-and-minutes-of-the-current-time-into-macro/m-p/597900#M172321</link>
      <description>&lt;P&gt;if you want the same in open code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let hour=%sysfunc(hour(%sysfunc(time())));
%put &amp;amp;=hour;

%let minute=%sysfunc(minute(%sysfunc(time())));
%put &amp;amp;=minute;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 19 Oct 2019 16:43:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-take-hour-and-minutes-of-the-current-time-into-macro/m-p/597900#M172321</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-10-19T16:43:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to take hour and minutes of the current time into macro variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-take-hour-and-minutes-of-the-current-time-into-macro/m-p/597901#M172322</link>
      <description>Thanks. So, do I have to use %sysfunc for every nested function?</description>
      <pubDate>Sat, 19 Oct 2019 17:29:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-take-hour-and-minutes-of-the-current-time-into-macro/m-p/597901#M172322</guid>
      <dc:creator>braam</dc:creator>
      <dc:date>2019-10-19T17:29:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to take hour and minutes of the current time into macro variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-take-hour-and-minutes-of-the-current-time-into-macro/m-p/597902#M172323</link>
      <description>&lt;P&gt;Unfortunately yes. For every SAS function to be executed in open code, you would need a %sysfunc wrapper exclusively. The idea is to basically pave way for the macro processor to execute SAS functions that are typically executed by the datastep compiler or SQL processor. However the use of %sysfunc is required to use this at compile time or in other words while compiler tokenizes words or texts in the input stack. A process that's done by word scanner. This basically processes one token at a time in a queue.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 19 Oct 2019 17:34:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-take-hour-and-minutes-of-the-current-time-into-macro/m-p/597902#M172323</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-10-19T17:34:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to take hour and minutes of the current time into macro variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-take-hour-and-minutes-of-the-current-time-into-macro/m-p/597915#M172335</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/279507"&gt;@braam&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks. So, do I have to use %sysfunc for every nested function?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No, you can use the solution from &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt; and then zero %SYSFUNC calls are needed.&lt;/P&gt;</description>
      <pubDate>Sat, 19 Oct 2019 19:37:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-take-hour-and-minutes-of-the-current-time-into-macro/m-p/597915#M172335</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-10-19T19:37:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to take hour and minutes of the current time into macro variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-take-hour-and-minutes-of-the-current-time-into-macro/m-p/597926#M172346</link>
      <description>&lt;P&gt;If you already have a macro variable with a string like:&lt;/P&gt;
&lt;PRE&gt;16:45&lt;/PRE&gt;
&lt;P&gt;Then just use %SCAN() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let hh=%scan(&amp;amp;time,1,:);
%let mm=%scan(&amp;amp;time,2,:);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What do you want for HH or MM when the value is less than 10?&amp;nbsp; Do you want 9 or 09?&lt;/P&gt;</description>
      <pubDate>Sat, 19 Oct 2019 21:00:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-take-hour-and-minutes-of-the-current-time-into-macro/m-p/597926#M172346</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-19T21:00:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to take hour and minutes of the current time into macro variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-take-hour-and-minutes-of-the-current-time-into-macro/m-p/597928#M172348</link>
      <description>Thanks. I would like to have 09, but could you please let me know both?</description>
      <pubDate>Sat, 19 Oct 2019 21:24:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-take-hour-and-minutes-of-the-current-time-into-macro/m-p/597928#M172348</guid>
      <dc:creator>braam</dc:creator>
      <dc:date>2019-10-19T21:24:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to take hour and minutes of the current time into macro variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-take-hour-and-minutes-of-the-current-time-into-macro/m-p/597931#M172351</link>
      <description>&lt;P&gt;The MONTH() or DAY() function return a number, so if you want the leading zero the use the Z format.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let now=%sysfunc(time());
%let hh=%sysfunc(hour(&amp;amp;now),z2.);
%let mm=%sysfunc(minute(&amp;amp;now),z2.);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note if you call TIME() twice there is small risk that you will accidentally convert 10:59 into 10:00 if the clock ticks over from 10:59 to 11:00 between the two calls.&amp;nbsp; Better the save the value once and the use it twice.&lt;/P&gt;</description>
      <pubDate>Sat, 19 Oct 2019 21:47:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-take-hour-and-minutes-of-the-current-time-into-macro/m-p/597931#M172351</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-19T21:47:05Z</dc:date>
    </item>
  </channel>
</rss>

