BookmarkSubscribeRSS Feed
rajredy7172012
Calcite | Level 5

Hi:

I would like to copy some excel files from one location to another in SAS. Can't find the best solution out there. Let's say in the source folder, I have 5 files and I want to only copy 3 files to the destination folder. The filenames are random. What is the best solution? I tried Fcopy but didn't work.

Thanks,

Rajesh.

5 REPLIES 5
Reeza
Super User

What do you mean by FCOPY didn't work? It's the solution that should work regardless of OS

Please post your code/log. 

 

To do this, you require access to both locations from SAS/SAS Server and you need to know which files. 

You can select randomly but that's a very unusual requirement, usually it's most recent/latest or specific ones. 

Other options are Pipe or X commands, do you know if you have XCMD option enabled?

 

 

 

rajredy7172012
Calcite | Level 5

/* these IN and OUT filerefs can point to anything */
filename in 'Y:\Raw_DS\Neratinib\5201_v6\Output\Programmed Listings new url\L1.xlsx';
filename out 'M:\L1.xlsx';

/* copy the file byte-for-byte */
data _null_;
length filein 8 fileid 8;
filein = fopen('in','I',1,'B');
fileid = fopen('out','O',1,'B');
rec = '20'x;
do while(fread(filein)=0);
rc = fget(filein,rec,1);
rc = fput(fileid, rec);
rc =fwrite(fileid);
end;
rc = fclose(filein);
rc = fclose(fileid);
run;

filename in clear;

filename out clear;

Reeza
Super User
What's the purpose of this code? Is this what you tried? I don't see FCOPY being sued anywhere....
andreas_lds
Jade | Level 19

If xmcd is enabled and no plans exist to migrate your sas-environment to another os, use it.

Kurt_Bremser
Super User

Please post the code you used.

Do you want to randomly select 3 files from the 5 that are there, or is it just that the number of files present is arbitrary, and you need to select according to a rule?

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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