 ds_wait.sas
 ds_wait.sas
/***************************************************************************\
* MACRO:      ds_wait, wait for access to a dataset                         *
*                                                                           *
* Author:     Richard A. DeVenezia, 10/1/92                                 *
*                                                                           *
* Purpose:    Check a dataset for accessibility, if it is not               *
*             (generally not available if dataset is                        *
*             concurrently open) wait &seconds (upto 10 times)              *
*                                                                           *
* Arguments:  data - Dataset name to check                                  *
*             seconds - How long to wait before retrying                    *
\***************************************************************************/
%macro ds_wait ( data, seconds);
  options nonotes nomprint;
  %local N N_STOP;
  %let N = 0;
  %let N_STOP = 10;
  %do %until (&syserr=0);
    data _null_; call symput('time', put (time(), time8.)); run;
    data _null_; set &data; stop; run;
    %if (&syserr ne 0) %then %do;
      %put &time Could not acess &data;
      %put SYSERR=&syserr, will wait &seconds seconds and try again;
      run;
      %let N = %eval(&N+1);
      %if &N = &N_STOP %then %do;
        %put Aborting after &N retries on &data;
        endsas;
      %end;
      %else %do;
        x "sleep &seconds";
      %end;
    %end;
    %else
      %put &time &data is accessible;
  %end;
  options notes mprint;
%mend;