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.
SASuserlot
Barite | Level 11

Can we use the SAS to rename the file name that already existed in the folders using the  system commands? if so can you please tell me how to achieve this:

Folder: "c\documents\study

Old filename: stdy_details.xlsx

New Name: Stdy2022.xlsx

I want to rename the old file with new name.   If possible both ways using base SAS and X command .Thanks for your time. 

1 ACCEPTED SOLUTION

Accepted Solutions
sbxkoenk
SAS Super FREQ
*proc options; *run;

options noxwait;
x 'cd C:\documents\study';
x 'ren stdy_details.xlsx Stdy2022.xlsx';
/* end of program */

Koen

View solution in original post

6 REPLIES 6
sbxkoenk
SAS Super FREQ

Hello,

 

With the SAS RENAME function , you can also rename external files !

 

See here :

SAS® 9.4 and SAS® Viya® 3.5 Programming Documentation | SAS 9.4 / Viya 3.5
Functions and CALL Routines
RENAME Function
Renames a member of a SAS library, an entry in a SAS catalog, an external file, or a directory.
https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p14axci3mo3egan1okbcydvbt43...

 

Koen

SASuserlot
Barite | Level 11

Thank you. Is it possible using x commands?

sbxkoenk
SAS Super FREQ

Of course, with X-command or CALL SYSTEM.

Unless your SAS administrator has disabled that functionality in the configuration file.

 

option XCMD enables the X command in SAS.

option noXCMD disables the X command in SAS.

 

Koen

SASuserlot
Barite | Level 11

Thank you, if possible can you please give me an example how to rename  a file using x command using SAS. I am not that great with he x commands in SAS. in the following scenario

 

Folder: "c\documents\study

Old filename: stdy_details.xlsx

New Name: Stdy2022.xlsx

sbxkoenk
SAS Super FREQ
*proc options; *run;

options noxwait;
x 'cd C:\documents\study';
x 'ren stdy_details.xlsx Stdy2022.xlsx';
/* end of program */

Koen

SASuserlot
Barite | Level 11

Thank you. It worked for me.

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Early bird rate extended! Save $200 when you sign up by March 31.

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
  • 2074 views
  • 3 likes
  • 2 in conversation