BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
duanzongran
Obsidian | Level 7

dear all:

The code is:

data  test;
input x $1.;
datalines;
a
b
c
;
run;

%macro test();
ods listing close ;
ods results off;
filename fbout "D:\test.xlsx";

%let i=0;
%do %while(%eval(&i.)<10); 
ods excel (id=fb) file=fbout  options(sheet_interval="none" sheet_name="test");

proc print data=test;run;
%let i=%eval(&i.+1);
%end;

ods excel (id=fb) close;

filename fbout clear;
ods listing  ;
ods results on;

%mend;

%test();

when the code is running ,I break it for some reason.But when I rerun the code ,logs shows as below:

"

ERROR: At least one file associated with fileref FBOUT is still in use.
ERROR: Error in the FILENAME statement.
"

************some other logs*******

 

"ERROR: File is in use, D:\test.xlsx.
"


The only way I know  to fix the error is  close  SAS,delete the xlsx-file in windows OS ,restart SAS. Is there any other method to fix it?

Any suggestion is welcom!

Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Why are you opening and closing the file so many times?

Do you even need to use the FILENAME statement?  You can just specify the actual file in the ODS statement.

Why are you working so hard to re-invent a basic DO loop?

 

ods excel (id=fb) file= "D:\test.xlsx" options(sheet_interval="none" sheet_name="test"); 
%do i=0 %to 9 ;
proc print data=test;
run;
%end;
ods excel (id=fb) close;

 

View solution in original post

1 REPLY 1
Tom
Super User Tom
Super User

Why are you opening and closing the file so many times?

Do you even need to use the FILENAME statement?  You can just specify the actual file in the ODS statement.

Why are you working so hard to re-invent a basic DO loop?

 

ods excel (id=fb) file= "D:\test.xlsx" options(sheet_interval="none" sheet_name="test"); 
%do i=0 %to 9 ;
proc print data=test;
run;
%end;
ods excel (id=fb) close;

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 1 reply
  • 292 views
  • 1 like
  • 2 in conversation