Hello,
I need to copy a text file from one directory to another (in linux). I am using the following code -
filename infile "/cifs/test1/test2/test3/test.txt";
filename outfile "/cifs//test10/test20/test30/test.txt";
data _null_ ;
rc = fcopy(infile, outfile);
run;
I get rc 2004, and the file isn't copied. All help will be appreciate, Thank you.
The arguments to the FCOPY functions are character values, so they must be quoted, see example below. I would also recommend to use the SYSMSG function to get the proper error message back that corresponds to the return code.
data msg;
rc=fcopy("infile", "outfile");
length msg $ 1024;
msg=sysmsg();
putlog _all_;
run;
The arguments to the FCOPY functions are character values, so they must be quoted, see example below. I would also recommend to use the SYSMSG function to get the proper error message back that corresponds to the return code.
data msg;
rc=fcopy("infile", "outfile");
length msg $ 1024;
msg=sysmsg();
putlog _all_;
run;
Works great, Thank you!
Greetings,
I just trued this solution:
data msg;
rc=fcopy("C:\My Documents\schedule.txt", "C:\My Documents\Reports\schedule.txt");
length msg $ 1024;
msg=sysmsg();
putlog _all_;
run;
And received this SAS EG output:
rc msg
20004 ERROR: No logical assign for filename C:\MY.
@Hdababs wrote:
Greetings,
I just trued this solution:
data msg;
rc=fcopy("C:\My Documents\schedule.txt", "C:\My Documents\Reports\schedule.txt");
length msg $ 1024;
msg=sysmsg();
putlog _all_;
run;
And received this SAS EG output:
rc msg
20004 ERROR: No logical assign for filename C:\MY.
That cannot work because that is not what FCOPY wants as INPUT. It wants the names of the FILEREF you created with the FILENAME statement or FILENAME() function. Instead you gave it the actual path to the file. The error message is clearly saying there is no fileref named "C:\MY" (and there never could be since : and \ are not valid characters to use in a fileref).
Thank you. If I understand correct, I need to declare infile and outfile variables for the directory path for the source and destination.
@Hdababs wrote:
Thank you. If I understand correct, I need to declare infile and outfile variables for the directory path for the source and destination.
Kind of.
You need to DEFINE two filerefs. You can use INFILE and OUTFILE for them if you want (make sure you aren't already using those names for some other files that you still need to reference.). Or you can use any other valid SAS names that is 8 characters or less as the filerefs.
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.