BookmarkSubscribeRSS Feed
kashlik123
Obsidian | Level 7

I am trying to do a bootstrap sample of variables in a macro do loop. The code is similar to the macro shown below (NOTE: the code below works fine. It is the real dataset, which I cannot share here, where the problem occurs):

%Macro test();
	%Do x = 1 %to 10;
		data cars;
		set sashelp.cars;
		run;

		Proc surveyselect
		Data=cars
		Method=urs
		Seed=90
		Samprate=0.5
		Reps=100
		Out=cars_sample;
		Run;

	/*Do something with the sample for each iteration*/
	%End;
%Mend;

On the second iteration SAS tell me that the dataset is locked:

ERROR: You cannot open WORK.CARS_SAMPLE.DATA for output access with member-level control because WORK.CARS_SAMPLE.DATA is in use 
by you in resource environment IOM ROOT COMP ENV.

The dataset is certainly not open by any other user (this is confirmed because when I close SAS and start the session again the dataset unlocks), neither is it open by me in any other program.

 

How can I solve this issue?

 

10 REPLIES 10
kashlik123
Obsidian | Level 7

Do you mean tools - options - data general - Automatically import data when added to project? Or something else?

kashlik123
Obsidian | Level 7

My version is 8.1 and there is no such option

kashlik123_0-1628606773580.png

 

jimbarbour
Meteorite | Level 14

If you are using EG 8, it would look something like the below.

 

Jim

jimbarbour_0-1628607340759.png

 

kashlik123
Obsidian | Level 7

Thank for the reply, but unfortunately it does not work

Reeza
Super User
It could be in the rest of your code. Without the full code and log not sure we can actually answer this.
Reeza
Super User
And make sure to restart EG between the change and test.
Tom
Super User Tom
Super User

Try making a different dataset each time through the loop.  

%do x = 1 %to 10;
...
  Out=cars_sample&x
...
ballardw
Super User

An aside, when you use a specific seed value in Proc Surveyselect with the same input data set and other options/parameters the resulting data is exactly the same. So running that particular Surveyselect code generates the same data set 10 times.

 

I know you are saying "like this" but if the code is close enough to the example there is a certain amount of repeating the same thing for the exact same sample.

 

And the likely issue is in the

/*Do something with the sample for each iteration*/

Possibly one of the procedures like Proc Datasets or Document that expects a Quit statement to end the procedure.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 10 replies
  • 991 views
  • 9 likes
  • 6 in conversation