BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Taliah
Quartz | Level 8

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.

1 ACCEPTED SOLUTION

Accepted Solutions
BrunoMueller
SAS Super FREQ

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;

View solution in original post

6 REPLIES 6
BrunoMueller
SAS Super FREQ

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;
Taliah
Quartz | Level 8

Works great, Thank you!

Hdababs
Obsidian | Level 7

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.

Tom
Super User Tom
Super User

@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).

Hdababs
Obsidian | Level 7

Thank you. If I understand correct, I need to declare infile and outfile variables for the directory path for the source and destination.

Tom
Super User Tom
Super User

@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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 4048 views
  • 0 likes
  • 4 in conversation