i need the sas code to move a file from a folder to another.
filename in "</path/for/input/file.ext>" lrecl=1 recfm=n;
filename out "</path/for/output/file.ext>" lrecl=1 recfm=n;
data _null_;
rc = fcopy("in","out");
rctxt=sysmsg();
if rc then
put rctxt;
run;
data _null_;
rc=rename('c:\temp\want.sas','c:\temp\a\want.sas','file');
run;
not working
"not working" on its own is a completely useless message. Describe in detail what does not work to your expectation, post the complete log of the failing step in a window opened with this button:
I am not obtaining any error, but the file is still in the same location.
The OS is windows.
The RENAME function handles one file at a time. To move multiple files, do not use wildcard characters. Use a DATA step with DOPEN, DNUM and DREAD to obtain filenames, and use RENAME for each item you find.
Use absolute path names; in Windows, this means they must start with a drive letter.
Post code as text in a code box ("little running man"), so we can use it in examples; do not post pictures.
To what @Ksharp and @Kurt_Bremser have already wrote, if you want to see more information about "why it didn't work?", use the following trick:
data _null_;
rc = rename(...);
rctxt=sysmsg();
if rc then
put rctxt;
run;
As a side note, if you need to get the files list but do not feel confident with the "DOPEN()"-family of functions , you can use the BasePlus SAS package and the %dirsAndFiles() macro to do the "give-me-the-list-of-files" job for you.
Bart
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.
Ready to level-up your skills? Choose your own adventure.