12-21-2017 06:19 AM
I've the requirement to convert a SAS Dataset to XML and then place to the specified location.Once it is done I've to move the Dataset to the archived folder.
I know to convert a SAS Dataset to XML but I'm not sure how to move the Dataset to the archived folder via SAS program. I'm using SAS EG and working in a server enviornment.
Appreciate if someone of you shed some light here.
12-21-2017 06:48 AM
Why would you want to? You have the file within the SAS system, use the SAS system to move the file. If you want to use the OS, you would need to have OS command access - something which is general not given - then you would need to provide full network paths from and to, ensuring that you/your SAS session has access to both.
If its for some specific thing outside the SAS system, then speak to your IT group about setting up an automated backup process which can move the file out. Its not really a good idea to do things yourself if you don't have the processes in place.
12-21-2017 11:19 AM
Is there any way we can do it with X command?
Sure, use the copy command but in 90% of EG installations X command is disabled.
You can also use FCOPY to move a file especially a non-SAS file.
If you want an X command, play around until your OS commands are correct then you bring them into SAS, but that's not a SAS question per se.
12-21-2017 07:52 AM
Define the target library, and use
proc datasets library=source nolist; copy out=target clone datecopy move ; select dataset; quit;
This will make your SAS program platform-independent.
Moving with operating system tools might only be necessary if you also need to preserve the original physical file (not dataset!) modification timestamp and access permissions. In that case, consult your operating system's documentation how to use the relevant commandline utility.
12-21-2017 03:55 PM
I assume that you got as far as to allocate an XML library and write to that. So what you have is a source path, which is the path of your XML library. And a destination path, which is the archive folder. And a member name, the name of the dataset that you wrote in the source path library.
You now have 3 options.
1: to allocate the destination path with an XML libname as well, and use proc copy to copy it to the archive library;
libname dest xml '<destination folder>'; proc copy in=<source lib> out=dest; select <dataset name>; run;
proc delete data=<source lib>.<dataset name>;
This is probably the slowest, as SAS may do some processing of variables etc. along the way. As shown here, it also lacks a check for a successful copy, so that the source table only gets deleted if the copy goes well.
2: to copy the generated XML file as a flat file, using the FCOPY function:
filename in '<source folder>\<dataset name>.XML'; filename out '<destination folder>\<dataset name>.XML'; data _null_; if fcopy('in','out') then do; msg=sysmsg(); put msg; end;
This is also portable, and probably as fast as it gets. And as you can see, it was quite simpe to put in a check for successful copy before deleting the input.
(3: Except if the source file is on the same physical disk as the archive folder, then you may get better performance using a native command to move the file, as it is only the reference to the file (the name of the directory) that needs to be changed, the actual file needs not be moved, But as others have already pointed out, you may not be allowed to use OS commands from your EG session anyway.)
01-16-2018 01:47 AM
When I tried the second method, I received an error as follows. Could you please help me to get rid of this error?
24 data _null_; 25 if fcopy('in','out') then do; _____ 68 ERROR 68-185: The function FCOPY is unknown, or cannot be accessed. 26 msg=sysmsg(); 27 put msg; 28 end; 29 else rc=fdelete('in'); 30 run;
01-16-2018 03:02 AM
01-16-2018 05:32 AM
01-16-2018 07:10 AM
The fcopy() function was introduced with SAS 9.4. It's way past time for your organization to migrate to 9.4.