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;

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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