Tips:Using the RENAME Function to Rename SAS Data Sets, Catalogs, OS Files, and Directories

From sasCommunity
Jump to: navigation, search

Did you know that you can rename SAS data sets, SAS catalog entries, as well as OS directories and files in directory-based operating systems from inside of a SAS DATA step?

The RENAME function, which is new in SAS 9.2, will let you do exactly that! It is great for SAS purists who do not want to use the X command or the CALL SYSTEM routine to “shell out” to the operating system to rename files and/or directories. And, if you have PROC DATASET phobia, you can use the RENAME function to rename SAS files.

Here is a simple example that renames “test.pdf” to “old.pdf” in the comfort and privacy of a DATA step. The nice thing about the RENAME function that differentiates it from the X command or the CALL SYSTEM routine is that you get a return code that you can query to make sure that your rename worked.

data _null_;
rc = rename('c:\temp\test.pdf', 'c:\temp\old.pdf', 'file');
put "*****************";
put "the return code is: " rc;
put "*****************";
run;

RENAME also works with %SYSFUNC. Intrigued? Well, then read more about it in the SAS Online Documentation via the link, below.

Submitted by The man who wrote the book on performance. Contact me at my Discussion Page.

....see also