Help using Base SAS procedures

SAS Macro To Kick Off Every 10 Minutes

Reply
Contributor
Posts: 24

SAS Macro To Kick Off Every 10 Minutes

I have a request to build a SAS Macro that fires off a SAS Program every day, in 10 minute intervals.

I am aware of the &SysDate, &SysDay and &SysTime variables and figure they will be used to calcuate the Day and Time (Not sure I need to worry about the &SysDate), but do not have much experience with SAS Macro's and %Do loops.

I know I'll need to add 10 minutes to the &SysTime variable and basically hold until the system clock and the &SysTime+10Min = the SystemTime.

I'm working on this now, but any insight or code would be helpfull.

Job will be running on UNIX and I am coding in SAS EG.

TIA, Jay

Super Contributor
Posts: 292

SAS Macro To Kick Off Every 10 Minutes

Would it not be wiser to use the Unix scheduler to kick off the program?

Trusted Advisor
Posts: 1,301

Re: SAS Macro To Kick Off Every 10 Minutes

Unix Scheduler:

Unix$> crontab -e

10 * * * * /path/to/sas -batch -noterminal -config path/to/sasconfig.cfg -sysin /path/to/code.sas -log /path/for/log.log -print /path/for/print.lst

SAS Macro (would not recommend):

%do until(&exception=1);

  %execution_macro

   data _null_;

    slept=sleep(60*10); /*sleep for 10 minutes */

   run;

/* sas statements to catch an exeception to stop loop */

%end;

Contributor
Posts: 24

Re: SAS Macro To Kick Off Every 10 Minutes

Cron and the UNIX Scheduler are not availiable.. Thanks I am looking at the above code(s)...

PROC Star
Posts: 7,474

Re: SAS Macro To Kick Off Every 10 Minutes

Could you use EG's own scheduler?  I'm not familiar with it, but an application is described in the paper at: http://www2.sas.com/proceedings/sugi29/156-29.pdf

Trusted Advisor
Posts: 1,301

Re: SAS Macro To Kick Off Every 10 Minutes

You can access the EG scheduler from the File>Schedule Project (the document above says it is under the Tools drop-down).  I have never used it before but basically anything would be preferable to a constantly running loop to execute a subsequent step once every 10 minutes...

Super User
Posts: 19,817

Re: SAS Macro To Kick Off Every 10 Minutes

I don't know if this works in Unix but in Windows you can 'pause' sas so 'pausing' for 10 minutes seems easier than trying to figure out the next run by looking at system time.

Definitely a brute force methodology. 

Frequent Contributor
Posts: 104

Re: SAS Macro To Kick Off Every 10 Minutes

Our outsourced UNIX server admins also removed cron from us, but gave us the 'at' command.  So we use at to re-schedule itself.  Here's an example from the 'at' command man pages:

To have a job reschedule itself,  at  can  be  invoked  from within  the  at-job.  For  example,  this "daily-processing" script named my.daily runs every day (although crontab is a more appropriate vehicle for such work).  Content of the my.daily file:

     # my.daily runs every day
     at now tomorrow < my.daily
     daily-processing

So, if you have access to at,

     change second line to 'at now + 10 minute < ...'

     change daily-processing to 'sas -batch -noterminal .........'

These operating system facilities is usually preferred than having one SAS long session that sleeps for 10 minutes then wakes up to do some stuff and the goes back to sleep.

Super User
Posts: 10,035

Re: SAS Macro To Kick Off Every 10 Minutes

Not sure whether it could work.

%do %until(count gt 100);* execute  code for one hundred;

.......................

count+1;

%include 'c:\report.sas';

call sleep(60,10); /*sleep for 10 minutes */

............

%end;

Ksharp

Ask a Question
Discussion stats
  • 8 replies
  • 1407 views
  • 0 likes
  • 7 in conversation