Hi,
I'm trying to make a program that if a table is locked by another process then the program should wait for 30 second for example, and then run again. I used the sleep function but with no success.
%let checklock = &syslckrc;
options symbolgen;
proc sql;
create table resultado (Tablas varchar(55) ,x num, fecha date);
/*MACRO*/
%macro trylock();
proc sql noprint;
select "LIBBEM.DIM_CURRENCY" into :table from libbem.dual;
data _null_;
dsid=0;
%do %until (dsid > 0 or &checklock <= 0);
dsid = open("&table");
if (dsid = 0) then do;
rc = sleep(30,1);
end;
%end;
if (dsid > 0) then do;
rc = close (dsid);
end;
run;
%put trying lock ...;
lock &table;
%put syslckrc=&syslckrc;
lock &table clear;
%put syslckrc=&syslckrc;
process:
proc sql noprint;
insert into resultado
select "&table", &syslckrc as lock_code, today()
from libbem.dual;
quit;
%mend trylock;
/*Calling Macro*/
%trylock (1);
/*Resultado*/
proc sql;
create table Open_Table_CBNKPRD as
select
sum(x) as x
from resultado;
quit;
Any help?
You are mixing data step and macro code in a way that won't work.
Use only data step code instead:
data _null_;
dsid=0;
do until (dsid > 0 or &checklock <= 0);
dsid = open("&table");
if (dsid = 0) then do;
rc = sleep(30,1);
end;
end;
if (dsid > 0) then do;
rc = close (dsid);
end;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.