Search code examples
timesasmacros

How do I refer to time using time8 format in a Macro %do statement in SAS?


I have a variable that stores the current time using the time8 format and I want a macro to run unless the current time is later than 1:00pm, example:

%let time_now=%sysfunc(time(),time8.);

%macro find;
    %do %until (&time_now. gt '13:00:00't);
    {Some Code here}
    %end;

%if &time_now gt '13:00:00't %then %do;
    %put WARNING: The file has not yet appeared and it is after 1pm;
    %abort cancel;
%end;
%mend find;
%find;

I've seen examples where '13:00:00't works in a data step, but it does not seem to be working for me here. What do I replace it with? (Note: I want it to be something similar to the time8. format, not a SAS time which I know would be 46,800, but that is much less clear about what time is being referred to. Also I am stubborn and want to figure this out.)

When I try '13:00:00't it says I am past the time allotted, but that is not true because it is before 1pm. When I try 46,800 it runs as expected so I know it is not a time zone issue. I have also tried using double quotes since it is in a macro but that has not worked either.


Solution

  • Use %SYSEVALF to evaluate a constant representation.

    %do %until ( %sysfunc(time()) > %sysevalf('13:00:00't) );