BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
dhruvakumar
Obsidian | Level 7

Dear All,

 

Please can you help to provide how to create the Folders in SAS and Rename the folders using the code. 

 

 

Many Thanks

Dhruva 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

@dhruvakumar wrote:

Dear KurtBremser,

 

Thanks for advice.If you don't mind can you help one example ...Thanks 


The documentation for each function has examples. Is there something unclear about them?

 

DCREATE()

https://documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=p1aj29pf4cxnirn15q5hmf0tv438.htm...

data one;                                                                                                                                     
/* To create a new directory in the UNIX operating environment, using the name                                                                
   that is stored in the variable DirectoryName, follow this form: */                                                                         
                                                                                                                                              
 NewDirectory=dcreate(DirectoryName, '/local/u/abcdef/');                                                                                     
                                                                                                                                              
/* To create a new directory in the Windows operating environment, using the name                                                             
   that is stored in the variable DirectoryName, follow this form: */                                                                         
                                                                                                                                              
NewDirectory=dcreate(DirectoryName, 'd:\testdir\');                                                                                           
                                                                                                                                              
run;

RENAME()

 

Example 1: Renaming Data Sets and Catalog Entries
The following examples rename a SAS data set from Data1 to Data2, and also rename a catalog entry from A.SCL to B.SCL.
rc1=rename('mylib.data1', 'data2');
rc2=rename('mylib.mycat.a.scl', 'b', 'catalog');
Example 2: Renaming an External File
The following examples rename external files.
   /* Rename a file that is located in another directory. */
rc=rename('/local/u/testdir/first',
          '/local/u/second', 'file');
   /* Rename a PC file. */
rc=rename('d:\temp', 'd:\testfile', 'file');
Example 3: Renaming a Directory
The following example renames a directory in the UNIX operating environment.
rc=rename('/local/u/testdir/', '/local/u/oldtestdir', 'file');
Example 4: Renaming a Generation Data Set
The following example renames the generation data set Work.One to Work.Two, where the password for Work.One#003 is my-password.
rc=rename('work.one', 'two',,, 3,'my-password');

https://documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=p14axci3mo3egan1okbcydvbt433.htm...

 

I highly suggest bookmarking this page, it's a good organization of functions organized by category

https://documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=n01f5qrjoh9h4hn1olbdpb5pr2td.htm...

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

If you are talking about folders (directories) in the file system, look at the dcreate() and rename() functions.

 

If you are talking about SAS metadata folders, look at the METADATA procedure, but using it is NOT trivial.

dhruvakumar
Obsidian | Level 7

Dear KurtBremser,

 

Thanks for advice.If you don't mind can you help one example ...Thanks 

Reeza
Super User

@dhruvakumar wrote:

Dear KurtBremser,

 

Thanks for advice.If you don't mind can you help one example ...Thanks 


The documentation for each function has examples. Is there something unclear about them?

 

DCREATE()

https://documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=p1aj29pf4cxnirn15q5hmf0tv438.htm...

data one;                                                                                                                                     
/* To create a new directory in the UNIX operating environment, using the name                                                                
   that is stored in the variable DirectoryName, follow this form: */                                                                         
                                                                                                                                              
 NewDirectory=dcreate(DirectoryName, '/local/u/abcdef/');                                                                                     
                                                                                                                                              
/* To create a new directory in the Windows operating environment, using the name                                                             
   that is stored in the variable DirectoryName, follow this form: */                                                                         
                                                                                                                                              
NewDirectory=dcreate(DirectoryName, 'd:\testdir\');                                                                                           
                                                                                                                                              
run;

RENAME()

 

Example 1: Renaming Data Sets and Catalog Entries
The following examples rename a SAS data set from Data1 to Data2, and also rename a catalog entry from A.SCL to B.SCL.
rc1=rename('mylib.data1', 'data2');
rc2=rename('mylib.mycat.a.scl', 'b', 'catalog');
Example 2: Renaming an External File
The following examples rename external files.
   /* Rename a file that is located in another directory. */
rc=rename('/local/u/testdir/first',
          '/local/u/second', 'file');
   /* Rename a PC file. */
rc=rename('d:\temp', 'd:\testfile', 'file');
Example 3: Renaming a Directory
The following example renames a directory in the UNIX operating environment.
rc=rename('/local/u/testdir/', '/local/u/oldtestdir', 'file');
Example 4: Renaming a Generation Data Set
The following example renames the generation data set Work.One to Work.Two, where the password for Work.One#003 is my-password.
rc=rename('work.one', 'two',,, 3,'my-password');

https://documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=p14axci3mo3egan1okbcydvbt433.htm...

 

I highly suggest bookmarking this page, it's a good organization of functions organized by category

https://documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=n01f5qrjoh9h4hn1olbdpb5pr2td.htm...

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 3 replies
  • 6870 views
  • 3 likes
  • 3 in conversation