BookmarkSubscribeRSS Feed
Calcite | Level 5
Hey! I need a SAS program that will rename multiple files at once. Currently the files are names “blah_blah_person.pdf” and I need to update the files to “blah_blah_person_2023.pdf”. Is there a way to do this in SAS?

Please note that “blah_blah_person” is different for each file, it’s not a consistent name for each. And each file is located in a folder on my windows computer.
Super User Tom
Super User

just use TRANWRD().

data have;
  input oldname $200;

data want;
  set have;
   length newname $200;
   newname=tranwrd(oldname,'.pdf ','_2023.pdf');

Now that you have both names you can use them to generate RENAME commands.

Calcite | Level 5
Would the rename all of the files in the folder at once?
Super User Tom
Super User

@mollywilk wrote:
Would the rename all of the files in the folder at once?

To rename a series of files you need to:

1) Get the names of the files.

2) Generate the new name you want it to have.

3) Issue a rename command for each file.


What part of that are you having trouble with?

What have you tried?

How can you get a list of the files? (Hint that question has been asked hundreds of times on this site).

I showed you how to generate a new name.

How can you rename one file? What command can you use?  What would you do if it was just one file you had to rename?



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg



Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 2 in conversation