BookmarkSubscribeRSS Feed
Citrine10
Obsidian | Level 7

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;
2 REPLIES 2
Kurt_Bremser
Super User

Copy SAS datasets by assigning libraries and use PROC COPY.

Copy other files with the FCOPY function call. Use RECFM=N when creating the file references for this, if you need to copy binary files (like .xlsx).

Tom
Super User Tom
Super User

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;

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1778 views
  • 0 likes
  • 3 in conversation