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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.