<?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: SAS reading a time variable as a character during a do-loop? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-reading-a-time-variable-as-a-character-during-a-do-loop/m-p/75547#M16280</link>
    <description>You have to resolve date and time to numeric.&lt;BR /&gt;
This might work:&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
 call symput('START_TIME','9:30:00't);&lt;BR /&gt;
 call symput('END_TIME','16:00:00't);&lt;BR /&gt;
 call symput('INTERVAL_SECONDS',(15*60));&lt;BR /&gt;
 call symput('NO_INTERVALS',((&amp;amp;end_time-&amp;amp;start_time)/ &amp;amp;interval_seconds ));&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
You also need to use %BY instead of by in the macro loop....;-)&lt;BR /&gt;
%do time = &amp;amp;START_TIME %to &amp;amp;END_TIME %by &amp;amp;INTERVAL_SECONDS;&lt;BR /&gt;
//Fredrik</description>
    <pubDate>Thu, 26 Feb 2009 09:02:04 GMT</pubDate>
    <dc:creator>FredrikE</dc:creator>
    <dc:date>2009-02-26T09:02:04Z</dc:date>
    <item>
      <title>SAS reading a time variable as a character during a do-loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-reading-a-time-variable-as-a-character-during-a-do-loop/m-p/75545#M16278</link>
      <description>As far as I know, SAS times should be numeric, so I should be able to loop through the day in 15-minute intervals by converting the minutes to seconds. When I try to do that, though, I get the following error:&lt;BR /&gt;
&lt;BR /&gt;
ERROR: A character operand was found in the %EVAL function or %IF&lt;BR /&gt;
       condition where a numeric operand is required. The condition&lt;BR /&gt;
       was: &amp;amp;start_time&lt;BR /&gt;
ERROR: The %FROM value of the %DO TIME loop is invalid.&lt;BR /&gt;
ERROR: A character operand was found in the %EVAL function or %IF&lt;BR /&gt;
       condition where a numeric operand is required. The condition&lt;BR /&gt;
       was: &amp;amp;end_time by &amp;amp;interval_seconds&lt;BR /&gt;
ERROR: The %TO value of the %DO TIME loop is invalid.&lt;BR /&gt;
ERROR: The macro TAQDATA will stop executing.&lt;BR /&gt;
&lt;BR /&gt;
Code:&lt;BR /&gt;
&lt;BR /&gt;
%let start_time = '9:30:00't; /* starting time*/&lt;BR /&gt;
%let end_time = '16:00:00't; /* ending time (per Andersen)*/ &lt;BR /&gt;
%let interval_seconds = (15 * 60); /* interval length in seconds, note that total daily trading time should be divisible by interval length*/&lt;BR /&gt;
%let no_intervals = ((&amp;amp;end_time-&amp;amp;start_time)/ &amp;amp;interval_seconds )	; /*number  of intervals based on start/end time and length of intervals*/&lt;BR /&gt;
&lt;BR /&gt;
%do year = &amp;amp;start_year %to &amp;amp;end_year;&lt;BR /&gt;
	%do month = 1 %to 12;&lt;BR /&gt;
		%do time = &amp;amp;start_time %to &amp;amp;end_time by &amp;amp;interval_seconds;&lt;BR /&gt;
			%if (&amp;amp;year = 1996 or (&amp;amp;year = 2004 and &amp;amp;month&amp;gt;= 7)) %then %let fdatevar = datef;&lt;BR /&gt;
				%else %let fdatevar = fdate;&lt;BR /&gt;
			%let currentyear = %sysevalf(%substr(&amp;amp;year,3,2)); /*last two digits of year*/&lt;BR /&gt;
			%if %length(&amp;amp;month) = 1 %then %let currentmonth = 0&amp;amp;month;&lt;BR /&gt;
				%else %let currentmonth = &amp;amp;month; /* month in MM format*/&lt;BR /&gt;
			%let ctime=&amp;amp;time;&lt;BR /&gt;
			%let monthyearint = &amp;amp;currentyear&amp;amp;currentmonth&amp;amp;cinterval;&lt;BR /&gt;
			%if not(&amp;amp;year = &amp;amp;start_year and &amp;amp;month &amp;lt; &amp;amp;start_month) and not(&amp;amp;year = &amp;amp;end_year and &amp;amp;month &amp;gt; &amp;amp;end_month) and not (&amp;amp;ctime&amp;gt; &amp;amp;end_time) %then %&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
Any ideas greatly appreciated.</description>
      <pubDate>Thu, 26 Feb 2009 00:07:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-reading-a-time-variable-as-a-character-during-a-do-loop/m-p/75545#M16278</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-02-26T00:07:01Z</dc:date>
    </item>
    <item>
      <title>Re: SAS reading a time variable as a character during a do-loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-reading-a-time-variable-as-a-character-during-a-do-loop/m-p/75546#M16279</link>
      <description>A SAS constant for TIME as used in a DATA step is not equivalent to a time-formatted character string with a trailing "t".  This value is still treated as a character string.  If you need to process a macro using a time value, you will need to convert the character string to a SAS macro variable with a number that represents the equivalent time amount.&lt;BR /&gt;
&lt;BR /&gt;
This data conversion involves a %SYSFUNC macro function and an INPUT function to read the time-formatted macro variable.  For example, the SAS macro code below assigns a SAS number representing the current date (as days since 1/1/1960), then in a yyyy-mm-dd formatted value, as a character-string:&lt;BR /&gt;
&lt;BR /&gt;
%let today = %sysfunc(today());&lt;BR /&gt;
%put today is: &amp;amp;today;&lt;BR /&gt;
%let todaymdy = %sysfunc(putn(&amp;amp;today,yymmdd10.));&lt;BR /&gt;
%put today is: &amp;amp;todaymdy;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
I suggest you reply to the forum and explain what you are trying to accomplish, rather than attempting to try to debug your macro logic and coding.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Thu, 26 Feb 2009 03:02:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-reading-a-time-variable-as-a-character-during-a-do-loop/m-p/75546#M16279</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-02-26T03:02:10Z</dc:date>
    </item>
    <item>
      <title>Re: SAS reading a time variable as a character during a do-loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-reading-a-time-variable-as-a-character-during-a-do-loop/m-p/75547#M16280</link>
      <description>You have to resolve date and time to numeric.&lt;BR /&gt;
This might work:&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
 call symput('START_TIME','9:30:00't);&lt;BR /&gt;
 call symput('END_TIME','16:00:00't);&lt;BR /&gt;
 call symput('INTERVAL_SECONDS',(15*60));&lt;BR /&gt;
 call symput('NO_INTERVALS',((&amp;amp;end_time-&amp;amp;start_time)/ &amp;amp;interval_seconds ));&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
You also need to use %BY instead of by in the macro loop....;-)&lt;BR /&gt;
%do time = &amp;amp;START_TIME %to &amp;amp;END_TIME %by &amp;amp;INTERVAL_SECONDS;&lt;BR /&gt;
//Fredrik</description>
      <pubDate>Thu, 26 Feb 2009 09:02:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-reading-a-time-variable-as-a-character-during-a-do-loop/m-p/75547#M16280</guid>
      <dc:creator>FredrikE</dc:creator>
      <dc:date>2009-02-26T09:02:04Z</dc:date>
    </item>
  </channel>
</rss>

