Search code examples
directorysas

Create Directory in SAS using dlcreatdir then disable Option


I'm testing out using a simple piece of code to create directories that don't exist for my monthly SAS analysis so I don't have to manually do the pre-prep so to speak:

options dlcreatedir;
libname newdir "C:\Folder\&YYYYMM.\Inputs";

However I've read that using that options command essentially leaves it on for all subsequent pieces of code and I am worried that it might perform some messy writes on my disk if I make a mistake and leave it on.

Is there a way to turn it off once I am done creating directories?


Solution

  • If you review the documentation you'll notice it lists two options, DLCREATEDIR and NODLCREATEDIR. Use the second to turn off the option.

    option nodlcreatedir;
    

    http://support.sas.com/documentation/cdl/en/lesysoptsref/64892/HTML/default/viewer.htm#n1pihdnfpj4b32n1t62lx0zdsmdn.htm

    Another option is to use the DCREATE() function without changing the default options to create a folder explicitly rather than rely on the libname statement to create the folder.

     data _null_;
     folder = dcreate("Inputs", "C:\Folder\&YYYYMM.\");
     run;
    

    http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002986745.htm