BookmarkSubscribeRSS Feed
Macro_Man
Calcite | Level 5

I am reading in all of the XML files within a folder using the XMLV2 engine, and updating a dataset with the data contents of the files. After the update I run a macro which moves the XML files from the folder they are read in from to an archive folder. See code below:

 

Filename ReadIn Temp;
Libname ReadIn XMLV2 "&Exports.\&FileName." automap=replace xmlmap=ReadIn;

 

Proc Copy

     In=ReadIn
     Out=Work;
Run ;

...

/* Update Dataset */

...


%Macro Archive;
Options NoXWait;
Data _Null_;
Set File_List Nobs=Nobs;
Call Symput('Nobs',compress(Nobs));
Run ;

%Do i=1 %To &Nobs.;
Data _Null_ ;
Set File_List;
If _N_=&i. ;
Call Symput('Name',compress(Name));
Run ;

%Put Moving File &i. of &Nobs. - "&Name." to "&Exports.\Archive\&Name.";

X Move "&Exports.\&Name." "&Exports.\Archive\&Name." ;

%End ;
%Mend ;
%Archive ;

 

This process works without errors, but when archiving the files a few of them are not moved. If I close and reopen SAS and run the same code it works fine, so I am thinking the files are not being released after they are imported. Any ideas on how to release the files so they are free to be moved?

3 REPLIES 3
ChrisNZ
Tourmaline | Level 20

You could clear librefs and filerefs before moving the files.

libname  FX clear;
filename FF clear;

 

Macro_Man
Calcite | Level 5

Thanks for your reply. I had already tried the Libname <libref> Clear;  but did not think to try clearing the filename. When I added that statement the x command archived one of the files but not the other. I also tried Filename _ALL_ Clear; but that did not work either.

 

It seems like SAS is not disassociating with the most recently imported file. When I try to manually move the file in the Windows File Explorer I get the following File In Use message: "The action can't be completed because the file is open in SAS 9.4 for Windows" / "Close the file and try again."

ChrisNZ
Tourmaline | Level 20

Mmm that's odd.

You don't use the open function anywhere? Your steps are all closed with the proper run; or quit; statements?

You could also try to sleep just to ensure files are given enough time to be released, but if you come back later and can still see the problem in Windows, that's unlikely to help.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1183 views
  • 0 likes
  • 2 in conversation