SAS Programming

DATA Step, Macro, Functions and more
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.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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
  • 3183 views
  • 0 likes
  • 4 in conversation