在 Do While 或 Do Until 语句中执行 Proc SQL 语句

Execute Proc SQL Statement inside a Do While or Do Until Statement

我有一个 sql 数据库,可以在上午 4:00 到 7:00 上午的任何时间更新。我想要 运行 一个自动程序,一旦数据可用就会提取数据。它目前每 30 分钟检查一次。我已经编写了一个 SAS 程序来完成此操作,但我想压缩代码并在真正的循环中执行它。以下是我当前的代码。我总共重复代码块 1 七次。如果数据在第一次检查时可用,那么我的代码仍将执行 7 次。我希望它在第一次在 table 中找到数据后结束。我不懈地尝试创建一个循环,但所有努力都失败了。

%Let RecordCount = 0;/*Sets initial Record Count to 0*/
%Let min = 30;

/确定 SAS 将等待多少分钟,直到它尝试 收到0条记录后重新查询table/

data _NULL_; /*Get the previous Working Day based on todays date*/
  DateCheck = weekday(Today());
  Select (DateCheck);
  When (1) Do; 
        call symputx('_ReportDt',intnx('day',Today(),-2));
  end;
  When (2) Do;
    call symputx('_ReportDt',intnx('day',Today(),-3));
  end;                                    
  otherwise do;
    call symputx('_ReportDt',intnx('day',Today(),-1));
  end;
  end;
run;

/****************************1***************************/

Proc Sql noprint; 
  Select Count(ACCOUNT_NUMBER)
  Into :RecordCount separated by ' '
  From Table1 
  WHere Date = &_ReportDt;
Quit;

data _null_;
if &RecordCount = 0 then do;
                            wait_sec= (60*&min);
                            time_slept = sleep(wait_sec,1);
                        end;
                    else do;
end; 
run;

我找到了解决办法。下面是我能够开始工作的代码。我希望这可以帮助别人。

%MACRO SLEEP(MINUTES);
 DATA _NULL_;
 wait_sec= (60*&MINUTES);
 Var1 = sleep(wait_sec,1);
 RUN;
 %MEND SLEEP; 

 %MACRO DataCheck();
    Proc Sql noprint; 
        Select Count(ACCOUNT)
        Into :RecordCount separated by ' '
        From Table
        Where Date = &_ReportDt;
    Quit;
%DO %WHILE (&RecordCount = 0);
    Proc Sql noprint; 
        Select Count(ACCOUNT)
        Into :RecordCount separated by ' '
        From Table
        WHere Date = &_ReportDt;
    Quit;
    %SLEEP(15);/*Insert the number of Minutes that you want the program to sleep in between data checks.*/
%END;
 /*PROCESS*/
 %PUT "IT WORKED!";
%MEND DataCheck;

 data _null_;
 %DataCheck;
 run;