Help using Base SAS procedures

Cannot modify a dataset after using %SYSFUNC

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 128
Accepted Solution

Cannot modify a dataset after using %SYSFUNC

I keep getting this message after using %SYSFUNC:

ERROR: You cannot open WORK.OUT_14.DATA for output access with member-level control because WORK.TEMP_DATA.DATA is in use by you

in resource environment DMS Process.

I tried to make a macro variable to show how many columns in my SAS dataset. I used the code:

%let nvar=%sysfunc(attrn(%sysfunc(open(work.temp_data,i)),nvars));

but after using this code, I cannot modify TEMP_DATA any more. Smiley Sad

Any suggestions? Thanks!!


Accepted Solutions
Solution
‎03-28-2014 11:16 AM
PROC Star
Posts: 7,487

Re: Cannot modify a dataset after using %SYSFUNC

Still just guessing without seeing your code, but how about?:

%let dsid=%sysfunc(open(labimp.muestra1,i));

%let nvar=%sysfunc(attrn(&dsid.,nvars));

%let rc=%sysfunc(close(&dsid.));

p.s.  You'll probably have to start a new SAS session because, now, you have a number of opened files.

View solution in original post


All Replies
PROC Star
Posts: 7,487

Re: Cannot modify a dataset after using %SYSFUNC

I don't think %sysfunc is your problem but, rather, that you have opened and not closed the file.  Try issuing the following (untested) right after the line where you get the number of variables.  Without seeing your code I'm not sure how you would have to call it:

%let rc=%sysfunc(close(work.temp_data));


Frequent Contributor
Posts: 128

Re: Cannot modify a dataset after using %SYSFUNC

It doesn't work. Getting the following error:

ERROR: Argument 1 to function CLOSE referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.

ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list.  Execution of %SYSCALL statement or

       %SYSFUNC or %QSYSFUNC function reference is terminated.



------------------EDITED----------------


I also tried %sysfunc on my other datasets.

Getting the same error when I tried to modify the dataset again.

Solution
‎03-28-2014 11:16 AM
PROC Star
Posts: 7,487

Re: Cannot modify a dataset after using %SYSFUNC

Still just guessing without seeing your code, but how about?:

%let dsid=%sysfunc(open(labimp.muestra1,i));

%let nvar=%sysfunc(attrn(&dsid.,nvars));

%let rc=%sysfunc(close(&dsid.));

p.s.  You'll probably have to start a new SAS session because, now, you have a number of opened files.

Frequent Contributor
Posts: 128

Re: Cannot modify a dataset after using %SYSFUNC

Thanks Arthur! Your code works.

It seems like that I have to use %sysfunc(close() ) to close the opened file. Am I correct?

I used the following code to do the test. If I did not apply the %sysfunc(close() ) line, I would still get the same error.

--------------------------------------------

data temp_data2;

input t1 t2 t3; datalines;

1 2 3

;run;

%let dsid=%sysfunc(open(work.temp_data2,i));

%let nvar=%sysfunc(attrn(&dsid.,nvars));

%let rc=%sysfunc(close(&dsid.));

%put &nvar;

Super User
Super User
Posts: 7,074

Re: Cannot modify a dataset after using %SYSFUNC

Close those open datasets!

Normally SAS just generates sequential fileid numbers so you can try running something like this to close any that might have open.

data _null_;

do i=1 to 100;

   rc=close(i);

   put i= rc=;

end;

run;

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 2861 views
  • 2 likes
  • 3 in conversation