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;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.