BookmarkSubscribeRSS Feed
aashi77
Calcite | Level 5

i need the sas code to move a file from a folder to another.

9 REPLIES 9
yabwon
Amethyst | Level 16
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;
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Ksharp
Super User
data _null_;
rc=rename('c:\temp\want.sas','c:\temp\a\want.sas','file');
run;
aashi77
Calcite | Level 5

not working

Kurt_Bremser
Super User

picard-meme-facepalm.jpg

"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:

Bildschirmfoto 2020-04-07 um 08.32.59.jpg

Ksharp
Super User
?? I tested it before,no problem.
Is your OS Linux/Unix ,not Windows?
if it is Linux you need change your path from \ into /

data _null_;
rc=rename('/usr/tmp/want.sas','/root/sas/want.sas','file');
run;
aashi77
Calcite | Level 5

aashi77_0-1729491867231.png


I am not obtaining any error, but the file is still in the same location.
The OS is windows.

Ksharp
Super User
1)You must use absolute path(d:\saspret\fit\fit1\corm.csv ) not relative path (\saspret\fit\fit1\corm.csv) .

2)you can not use general mathed character(star) with filename like 'cram*.csv' , you need to specify it with total filename 'cram_1.csv' or 'cram_2.csv'.
Kurt_Bremser
Super User

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.

yabwon
Amethyst | Level 16

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

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



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
  • 9 replies
  • 1471 views
  • 4 likes
  • 4 in conversation