Search code examples
mysqlsqlsassas-macro

Delayed start of a program in SAS EG


Currently I'm running a program every morning for whilst I'm developing it so I can use today's data for it my problem is that it does take some time to run. I was wondering if anyone knew of some code I could write such that when I click run it will wait until a specific time to start. Currently I was thinking of adding a loop at the top to try and do this:

e.g.

%macro delay();
    data _null_;
         if %sysdate() >= 8:00 then %put Start;
         else %delay();
    run;
%mend;

Excuse the shoddy code writing, was doing this without SAS. Also I don't want to use any SQL servers like T-SQL.

Would making essentially an infinite loop be detrimental in anyway?


Solution

  • The WAKEUP() function can cause your SAS session to sleep until a specified time. There is also a SLEEP() function. WAKEUP() accepts date-time or time. From the docs:

    WAKEUP at a date-time:

    data _null_;
       slept=wakeup('01JAN2004:13:00:00'dt);
    run;
    

    WAKEUP at a time:

    data _null_;
       slept=wakeup("22:00:00"t);
    run;
    

    This should use less CPU resources than an infinite loop.