As the first step in the decommissioning of sasCommunity.org the site has been converted to read-only mode.


Here are some tips for How to share your SAS knowledge with your professional network.


Difference between revisions of "Tips:Using the RENAME Function to Rename SAS Data Sets, Catalogs, OS Files, and Directories"

From sasCommunity
Jump to: navigation, search
(Awesomely great; Let's see IIA match this .!.)
(gardening)
 
(6 intermediate revisions by 5 users not shown)
Line 1: Line 1:
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?   
+
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.
+
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 [[DATASETS procedure|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.
+
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.
 
<source lang="sas">
 
<source lang="sas">
 
data _null_;
 
data _null_;
rc = rename('c:\temp\test.pdf', 'c:\temp\old.pdf', 'file');
+
    rc = rename('c:\temp\test.pdf', 'c:\temp\old.pdf', 'file');
put "*****************";
+
    put "*****************";
put "the return code is: " rc;
+
    put "the return code is: " rc;
put "*****************";
+
    put "*****************";
 
run;
 
run;
 
</source>
 
</source>
RENAME also works with %SYSFUNC.   Intrigued? Well, then read more about it in the SAS Online Documentation via the link, below.
+
RENAME also works with [[%SYSFUNC]]. Intrigued? Well, then read more about it in the SAS Online Documentation via the link, below.
  
 
{{SubmittedBy|MMMMIIIIKKKKEEEE|The man who wrote the book on performance}}
 
{{SubmittedBy|MMMMIIIIKKKKEEEE|The man who wrote the book on performance}}
Line 19: Line 19:
  
 
<noinclude>
 
<noinclude>
[[Category:Tip to be Reviewed]]
+
[[Category:Tip in Use]]
 
[[Category:RENAME Function]]
 
[[Category:RENAME Function]]
[[Category:%SYSFUNC]]
+
[[Category:%SYSFUNC Function]]
 
</noinclude>
 
</noinclude>

Latest revision as of 09:04, 2 August 2017

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