Skip to content
9to5sas
  • Index
  • Glossary
Facebook Twitter Instagram Email RSS

  • Start Here
  • Base SAS
  • Advanced SASExpand
    • SAS Macros
    • PROC SQL
  • SAS/STATSExpand
    • SAS Analytics
    • Statistics
  • SAS Programs
9to5sas

9to5sas » SAS PROGRAMS » How to create folders using SAS?

How to create folders using SAS?

BySubhro Posted onAugust 18, 2020October 11, 2022 Last Updated:October 11, 2022
0 Comments

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.

How to create folders in SAS?

To create folders in SAS, there are a variety of system options, functions, and commands that you can use. 

This article will demonstrate some options and functions you can use to create a folder using SAS. These functions can be automated to perform repetitive routine tasks, avoid manual work, and save a great deal of time.

Page Contents

  • DLCREATEDIR System option
  • DCREATE
    • X md (an X Statement)
  • Deleting a Directory

DLCREATEDIR System option

DLCREATEDIR is a system option and can create folders when used with the libname statement.

options dlcreatedir;
libname newdir "/home/9to5sas/my_content/new";

Once you run the above statement, check the SAS log to see if the library assignment was successful or not.

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 the DLCREATEDIR option after creating directories.

The NODLCREATEDIR specifies not to create a directory for a SAS library 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 path name here.
  • Parent-directory 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 ‘test’, follow this syntax:

NewDirectory=dcreate('test', '/home/test/abc/');

Follow this syntax to create a new directory in the Windows operating environment with the directory name ‘test’.

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 the Unix Operating system to make directories.

data _null_;
x 'md /home/9to5sas/test';
run;

Deleting a Directory

This example uses FDELETE to delete an empty directory to which you have to 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 have 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.

Every week we'll send you SAS tips and in-depth tutorials

JOIN OUR COMMUNITY OF SAS Programmers!

Check your inbox or spam folder to confirm your subscription.

Post Tags: #create folders in sas#create folders using sas#dlcreatedir#dlcreatedir option in sas#how to create folders in sas#libname dlcreatedir
Subhro

Subhro Kar is an Analyst with over five years of experience. As a programmer specializing in SAS (Statistical Analysis System), Subhro also offers tutorials and guides on how to approach the coding language. His website, 9to5sas, offers students and new programmers useful easy-to-grasp resources to help them understand the fundamentals of SAS. Through this website, he shares his passion for programming while giving back to up-and-coming programmers in the field. Subhro’s mission is to offer quality tips, tricks, and lessons that give SAS beginners the skills they need to succeed.

Facebook Twitter Linkedin

Post navigation

Previous Previous
How to use the IN operator in SAS macro?
NextContinue
Date Interval Functions – INTNX and INTCK in SAS

SAS Tips in your inbox

Subscribe to 9to5sas for timely SAS tips and news delivered each month.
Learn about the latest articles, and code samples to keep your SAS skills fresh!

Your subscription is successful!

Recent Posts

  • Concatenate strings in SAS: The CAT Functions Demystified
  • 5 Techniques for Quickly Removing Leading Zeros in SAS
  • Troubleshoot Your Proc SQL Code Like a Pro with These 7 Automatic Macro Variables
  • 7 PROC SQL Options You Should Use to Debug Queries
  • How To Use The SAS Proc SQL Order By Statement?
9to5sas
  • Privacy Policy
  • Disclaimer
  • About
  • Contact
Facebook Twitter Instagram RSS Email Pinterest

Copyright © 2023 9TO5SAS, All rights reserved.

Scroll to top
  • 9to5sas Blueprint
  • About
  • About
  • Acceptable use policy
  • calculator
  • Confirm email
  • Contact
  • Contact
  • Cookie Policy
  • DISCLAIMER
  • Getting Started with SAS
  • Glossary
  • Index
  • Post #13801
  • Privacy Policy
  • Privacy policy
  • SAS Programs
  • Styles
  • Subscription confirmed
  • Terms and conditions
  • Thank You