Dear community,
I'm trying to copy files (any, not only SAS datasets) with fcopy function, particularly, in the following way:
/* to find the corresponding logical record length for a file */
data _null_;
infile "&source_file" lrecl=1073741823 length=rlen end=last;
input;
retain lrecl;
lrecl=max(lrecl, rlen);
if last then call symputx('rlen', lrecl);
run;
filename in "&source_file" lrecl=&rlen;
filename out "&dest_file" lrecl=&rlen;
data _null_;
length msg $ 384;
rc=fcopy('in', 'out');
if rc=0
then put 'Copied SRC to DEST.';
else do;
msg=sysmsg();
putrc= msg=;
end;
run;
I have also tried omitting the first data step and using lrecl=1073741823 for all files but the same result follows, which is the destination file has a slightly different size than the source file. Just in case I am comparing the sizes using the following code:
%let rc=%sysfunc(filename(insize, &source_file);
%let rc=%sysfunc(filename(outsize, &dest_file);
%let fidin=%sysfunc(fopen(&insize));
%let fidout=%sysfunc(fopen(&outsize));
%let bytes_source=%sysfunc(finfo(&fidin,File Size (bytes)));
%let bytes_dest=%sysfunc(finfo(&fidout,File Size (bytes)));
%put bytes_source= &bytes_source bytes_dest= &bytes_dest;
I don't get any error messages though I used to get before adding the lrecl option to the filename statement because the length of the logical record of the files I'm transferring often exceed the standard length of the option (32 767) but I've found out in one of related posts here that lrecl actually can take values up to 1GB.
I am using SAS EG 9.4 on a Unix server so I can't access admin options.
Thank you in advance!
As per this handy article, if you use RECFM=N then LRECL shouldn't be an issue
There's also the "old fashioned" approach of moving byte by byte: https://core.sasjs.io/mp__binarycopy_8sas_source.html
As per this handy article, if you use RECFM=N then LRECL shouldn't be an issue
There's also the "old fashioned" approach of moving byte by byte: https://core.sasjs.io/mp__binarycopy_8sas_source.html
To get a true "binary" copy, use RECFM=N in your FILENAME statements (or functions).
Edit: changed incorrect F to N in the RECFM.
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 25. 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.