I have a sql database that updates anywhere from 4:00 am to 7:00 am in the morning. I want to run an automated program that will extract the data once it is available. It currently check every 30 minutes. I have written a SAS program that will accomplish this but I would like to condense the code and execute it in a true loop. Below is my current code. I repeat the block of code 1 a total of seven times. If the data is available on the first check then my code will still execute 7 times. I would like it to end after the first time it finds data in the table. I have tried relentlessly to create a loop but have failed in all efforts.
%Let RecordCount = 0;/*Sets initial Record Count to 0*/
%Let min = 30;
/Determines how many minutes SAS will wait till it attempts to requery the table after receiving 0 records/
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;
I was able to find a solution. Below is the code I was able to get to work. I hope this can help someone else.