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?
You could clear librefs and filerefs before moving the files.
libname FX clear;
filename FF clear;
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."
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.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: