BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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:

ERROR: A character operand was found in the %EVAL function or %IF
condition where a numeric operand is required. The condition
was: &start_time
ERROR: The %FROM value of the %DO TIME loop is invalid.
ERROR: A character operand was found in the %EVAL function or %IF
condition where a numeric operand is required. The condition
was: &end_time by &interval_seconds
ERROR: The %TO value of the %DO TIME loop is invalid.
ERROR: The macro TAQDATA will stop executing.

Code:

%let start_time = '9:30:00't; /* starting time*/
%let end_time = '16:00:00't; /* ending time (per Andersen)*/
%let interval_seconds = (15 * 60); /* interval length in seconds, note that total daily trading time should be divisible by interval length*/
%let no_intervals = ((&end_time-&start_time)/ &interval_seconds ) ; /*number of intervals based on start/end time and length of intervals*/

%do year = &start_year %to &end_year;
%do month = 1 %to 12;
%do time = &start_time %to &end_time by &interval_seconds;
%if (&year = 1996 or (&year = 2004 and &month>= 7)) %then %let fdatevar = datef;
%else %let fdatevar = fdate;
%let currentyear = %sysevalf(%substr(&year,3,2)); /*last two digits of year*/
%if %length(&month) = 1 %then %let currentmonth = 0&month;
%else %let currentmonth = &month; /* month in MM format*/
%let ctime=&time;
%let monthyearint = &currentyear&currentmonth&cinterval;
%if not(&year = &start_year and &month < &start_month) and not(&year = &end_year and &month > &end_month) and not (&ctime> &end_time) %then %
;

Any ideas greatly appreciated.
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.

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:

%let today = %sysfunc(today());
%put today is: &today;
%let todaymdy = %sysfunc(putn(&today,yymmdd10.));
%put today is: &todaymdy;


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.

Scott Barry
SBBWorks, Inc.
FredrikE
Rhodochrosite | Level 12
You have to resolve date and time to numeric.
This might work:

data _null_;
call symput('START_TIME','9:30:00't);
call symput('END_TIME','16:00:00't);
call symput('INTERVAL_SECONDS',(15*60));
call symput('NO_INTERVALS',((&end_time-&start_time)/ &interval_seconds ));
run;

You also need to use %BY instead of by in the macro loop....;-)
%do time = &START_TIME %to &END_TIME %by &INTERVAL_SECONDS;
//Fredrik

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 765 views
  • 0 likes
  • 3 in conversation