BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
nnl3256
Obsidian | Level 7
There is data step and a table named fname is created. It is used in a macro. At end of the macro table is closed. When I rerun data step with modification in the same session, the table cannot be accessed. The error message: "ERROR: You cannot open WORK.FNAME.DATA for output access with member-level control because WORK.FNAME.DATA is in use by you in resource environment DMS Process." How can I re-use this table after the macro is completed? SAS code: data fname ; length id $2 name $10; input id $1-2 name $4-14; cards; aa TJC ;; run; %macro loopthrulst(list=); %let id=%sysfunc(open(&list)); %let NObs=%sysfunc(attrn(&id,NOBS)); %syscall set(id); %do i=1 %to &NObs; %let rc=%sysfunc(fetchobs(&id,&i)); %put # # # Display ORG name:&name # # #; %end; %let rc2=sysfunc(close(&id)); %mend; %loopthrulst(list=fname);
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Formatting your code and question so we can properly read it is very helpful. 

 

You're misisng the % on the last SYSFUNC call. 

 

This works for me, note I changed ID to DSID to avoid any confusion between the ID variable and the ID macro variable. 

 

data fname;
	length id $2 name $10;
	input id $1-2 name $4-14;
	cards;
 aa TJC 
;;
run;


options mprint symbolgen;
%macro loopthrulst(list=);

	%let dsid=%sysfunc(open(&list));
	%let nobs = %sysfunc(attrn(&dsid, NOBS));

	%syscall set(dsid);

	%do i=1 %to &nobs;
	  %let rc = %sysfunc(fetchobs(&dsid, &i));
	   %put # # # Display ORG name: &name # # #; 
    %end;
	%let rc2=%sysfunc(close(&dsid));


%mend;

%loopthrulst(list=fname);

@nnl3256 wrote:
There is data step and a table named fname is created. It is used in a macro. At end of the macro table is closed. When I rerun data step with modification in the same session, the table cannot be accessed. The error message: "ERROR: You cannot open WORK.FNAME.DATA for output access with member-level control because WORK.FNAME.DATA is in use by you in resource environment DMS Process." How can I re-use this table after the macro is completed? SAS code: data fname ; length id $2 name $10; input id $1-2 name $4-14; cards; aa TJC ;; run; %macro loopthrulst(list=); %let id=%sysfunc(open(&list)); %let NObs=%sysfunc(attrn(&id,NOBS)); %syscall set(id); %do i=1 %to &NObs; %let rc=%sysfunc(fetchobs(&id,&i)); %put # # # Display ORG name:&name # # #; %end; %let rc2=sysfunc(close(&id)); %mend; %loopthrulst(list=fname);

 

View solution in original post

3 REPLIES 3
ballardw
Super User

The error message you show typically means that you have some sort of view of the data set open. Either the data portion in VIEWTABLE or perhaps the column or properties view. That will need to be closed before other use. The "DMS Process" mentioned is the SAS Display Manager or the "Base SAS" or "Foundation SAS" program. If the data set is open that will cause the Open function to fail and return the error message.

 

Your code will be more readable if you copy from the SAS editor and paste into a code box opened with either the {I} or "running man" icon.

Reeza
Super User

Formatting your code and question so we can properly read it is very helpful. 

 

You're misisng the % on the last SYSFUNC call. 

 

This works for me, note I changed ID to DSID to avoid any confusion between the ID variable and the ID macro variable. 

 

data fname;
	length id $2 name $10;
	input id $1-2 name $4-14;
	cards;
 aa TJC 
;;
run;


options mprint symbolgen;
%macro loopthrulst(list=);

	%let dsid=%sysfunc(open(&list));
	%let nobs = %sysfunc(attrn(&dsid, NOBS));

	%syscall set(dsid);

	%do i=1 %to &nobs;
	  %let rc = %sysfunc(fetchobs(&dsid, &i));
	   %put # # # Display ORG name: &name # # #; 
    %end;
	%let rc2=%sysfunc(close(&dsid));


%mend;

%loopthrulst(list=fname);

@nnl3256 wrote:
There is data step and a table named fname is created. It is used in a macro. At end of the macro table is closed. When I rerun data step with modification in the same session, the table cannot be accessed. The error message: "ERROR: You cannot open WORK.FNAME.DATA for output access with member-level control because WORK.FNAME.DATA is in use by you in resource environment DMS Process." How can I re-use this table after the macro is completed? SAS code: data fname ; length id $2 name $10; input id $1-2 name $4-14; cards; aa TJC ;; run; %macro loopthrulst(list=); %let id=%sysfunc(open(&list)); %let NObs=%sysfunc(attrn(&id,NOBS)); %syscall set(id); %do i=1 %to &NObs; %let rc=%sysfunc(fetchobs(&id,&i)); %put # # # Display ORG name:&name # # #; %end; %let rc2=sysfunc(close(&id)); %mend; %loopthrulst(list=fname);

 

nnl3256
Obsidian | Level 7

It works by adding missing %. Thanks

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
  • 3 replies
  • 615 views
  • 1 like
  • 3 in conversation