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;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: