BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
rodrichiez
Quartz | Level 8

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?

1 ACCEPTED SOLUTION
2 REPLIES 2
Kurt_Bremser
Super User

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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1198 views
  • 1 like
  • 3 in conversation