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 lets 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:
data _null_;
rc = rename('c:\temp\test.pdf',
'c:\temp\old.pdf', 'file');
put "*****************";
put "the
return code is: " rc;
put "*****************";
run;
The example above renames “test.pdf” to “old.pdf” in 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.
Intrigued? Well, then read more
about it in the SAS online documentation on support.sas.com
Best
of luck in all your SAS endeavors!
---MMMMIIIIKKKKEEEE
(aka Michael A. Raithel)
Author of the
new cult classic for computer programmers: It Only Hurts When I
Hit <ENTER>
Print edition: http://tinyurl.com/z8bzx2e
Kindle edition: http://tinyurl.com/zypgqa7
The hack above is an
excerpt from the book: Did
You Know That? Essential Hacks for Clever SAS Programmers
Print edition: http://tinyurl.com/z8bzx2e
Kindle edition: http://tinyurl.com/zypgqa7
No comments:
Post a Comment