BookmarkSubscribeRSS Feed
Babloo
Rhodochrosite | Level 12

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.

13 REPLIES 13
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Its very simple, create libname to the archive folder, then do a proc copy from where it is to the archive lib.

Babloo
Rhodochrosite | Level 12

Is there any way we can do it with X command?

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Reeza
Super User

@Babloo wrote:

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.

 

 

Kurt_Bremser
Super User

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.

s_lassen
Meteorite | Level 14

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>;
run;

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;
else rc=fdelete('in');
run;

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.)

 

Babloo
Rhodochrosite | Level 12

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;
Babloo
Rhodochrosite | Level 12

No, I ran the code in SAS EG 7.1 and it is connected to UNIX server.

Babloo
Rhodochrosite | Level 12

SAS 9.2

Reeza
Super User

If it's EG 7.13 use the Copy Files Task

https://blogs.sas.com/content/sasdummy/2016/11/14/copy-files-task-moved-menus/

 

Otherwise, SAS 9.2 is a decade old. 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 13 replies
  • 1473 views
  • 4 likes
  • 5 in conversation