Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using SAS to copy a text file

Tags:

sas

Is there a SAS procedure / function which can be used to copy a text file from one location to another?

Of course this can be achieve using OS commands (%sysexec copy) but surely there must be an OS-agnostic way to do this?

From what I can tell by looking at the documentation, proc copy (or proc cport) only relate to SAS files..

like image 766
Allan Bowe Avatar asked Oct 24 '12 09:10

Allan Bowe


People also ask

How do I move a file in SAS?

The MOVEFILE function moves a file. The directory structure must already be in place for the function to move the file to its new location. If the target file already exists, the file is not moved and false is returned.


1 Answers

The simplest method is something like:

 data _null_;
    infile 'c:\input.txt';
    file 'c:\output.txt';
    input;
    put _infile_;
 run;

The method presented by RawFocus will copy any file, in binary, one byte at a time from input to output. For a text file this isn't necessary and doing the above will copy the file one line at a time. You may have to be slightly careful with record lengths, I believe that the default record length is 256, so you may need to put an explicit

 lrecl=32767

option or similar on the infile statement, as in

infile 'c:\input.txt' lrecl=32767;
like image 133
Tom Quarendon Avatar answered Nov 16 '22 03:11

Tom Quarendon