Hi there, I am trying to copy over csv, xlsx and .sas7bdat files from one folder to another. All these files have data within them, however when it I try opening the .sas7bdat file I get an error message saying "Attempt to reference a page past end-of-file on datasetname.data.
This is the code I am using:
filename src "mysrc/&file1."; filename dst "&test/&file1."; data _null_; infile src; file dst; input; put _infile_; run; filename src clear; filename dst clear;
If you have XCMD option enabled just use operating system commands to copy the files. It will be much faster. Use a PIPE so you can see any error messages the operating system returns.
data _null_;
infile "cp ""mysrc/&file1."" ""&test/&file1."" &2>1" pipe;
input;
put _infile_;
run;
If not then use FCOPY() to copy the files. Make sure to let it know it should copy them as BINARY files so you don't get the corruption caused by treating them as lines of text like your program did.
filename src "mysrc/&file1." recfm=n;
filename dst "&test/&file1." recfm=n;
data _null_;
rc=fcopy('src','dest');
run;
filename src ;
filename dst ;
If you have the list of FILENAMES in a dataset you skip generating all of those macro variables. Just use one data step to define the filerefs using the FILENAME() function copy the files.
Something like this (untested)
data results;
set filelist;
length src dst $ 8 ;
rc1=filename(src,source_file,,'recfm=n');
rc2=filename(dst,dest_file,,'recfm=n');
rc3=fcopy(src,dst);
rc4=filename(src);
rc5=filename(dst);
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: