Search notes:

SAS data step: file handling

Copying a file

With a combination of infile and file, a file can be copied within a data step.
%let cpDir = /share/home/tq84/sas/copyFile;
%put &=cpDir;

/* Using the x statement to create a file: */
x echo Line one>      &cpDir/orig.txt;
x echo Another line>> &cpDir/orig.txt;
x echo Third line>>   &cpDir/orig.txt;
x echo etc...>>       &cpDir/orig.txt;


/* Define filerefs for source and destination file: */
filename src "&cpDir/orig.txt";
filename dst "&cpDir/copy.txt";

/* Run the datastep to copy src to dst */
data _null_;
      infile  src;
      file    dst;
      input;
      put _infile_;
run;

/* Clear filerefs: */
filename src clear;
filename dst clear;
Github repository about-SAS, path: /programming/data-step/file/copy-file.sas
See also Bytewise copy of a file, put _infile_.

Index