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

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
Obsidian | Level 7

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.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 6 replies
  • 1826 views
  • 0 likes
  • 4 in conversation