HomeHow To

How to create folders in SAS?2 min read

Like Tweet Pin it Share Share Email

Table of Contents 1 DLCREATEDIR2 DCREATESyntax:X md (an X Statement)3 Deleting a Directory

To create folders in SAS, there are a variety of system options, functions and commands that you can use.  These tools can be automated to perform repetitive routine tasks and which avoid manual work and save a great deal of time.Enter your text here…

DLCREATEDIR

DLCREATEDIR is a system option used with the libname statement.

options dlcreatedir;libname newdir “/home/9to5sas/my_content/new”;

SAS Log:

NOTE: Library NEWDIR was created.NOTE: Libref NEWDIR was successfully assigned as follows: Engine: V9 Physical Name: /home/9to5sas/my_content/new

To create subfolders, you can use multiple specifications in the LIBNAME statement.

options dlcreatedir;libname newdir (“/home/9to5sas”,”/home/9to5sas/statistics”);

Important! Make sure to turn off DLCREATEDIR option after creating directories.

The NODLCREATEDIR specifies not to create a directory for a SAS library that is named in a LIBNAME statement.

DCREATE

DCREATE is a function that lets you create directories in your operating environment.

Syntax:

NewDirectory=DCREATE(‘Directory-name’, ‘parent-directory’);

  • Directory-name – It is the name of the directory to create. Do not include the pathname here.
  • Parent-directory – It is the complete pathname of the directory in which to create the new directory.

To create a new directory in the UNIX operating environment, with the directory name of ‘test’, follow this syntax:

NewDirectory=dcreate(‘test’, ‘/home/test/abc/’);

To create a new directory in the Windows operating environment, with the directory name of ‘test’, follow this syntax.

NewDirectory=dcreate(‘test’, ‘c:testdir’);

X md (an X Statement)

With the help of X statements, you can give UNIX operating system commands directly from SAS.

md is a command in Unix Operating system to make directories.

data _null_;x ‘md /home/subhroster20070/9to5sas/test’;run;

Deleting a Directory

This example uses FDELETE to delete an empty directory to which you have write access. If the directory is not empty, the optional SYSMSG function returns an error message stating that SAS is unable to delete the file.

filename testdir ‘physical-filename’;data _null_;rc=fdelete(‘testdir’);put rc=;msg=sysmsg();put msg=;run;

We hope this article helped you to create directories in SAS. Do you any tips to add Let us know in the comments.

Please subscribe to our mailing list for weekly updates. You can also find us on Instagram and Facebook.

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.