Select Page

The code below copies a file byte by byte – so can be used to copy any file, even pictures!  It is also platform agnostic (will work on both Unix and Windows).

%macro copyFile(in,out);
/* these IN and OUT filerefs can point to any file */
filename in “&in”;
filename out “&out”;
/* copy the file byte-for-byte  */
data _null_;
  length filein 8 fileid 8;
  filein = fopen(‘in’,‘I’,1,‘B’);
  fileid = fopen(‘out’,‘O’,1,‘B’);
  rec = ’20’x;
  do while(fread(filein)=0);
     rc = fget(filein,rec,1);
     rc = fput(fileid, rec);
     rc =fwrite(fileid);
  rc = fclose(filein);
  rc = fclose(fileid);
filename in clear;
filename out clear;

Credit for this code given to Chris Hemedinger!