BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
cleokatt
Calcite | Level 5

Hello, 
I'm trying to make SAS to create a folder when running a code and that's just: 

 

%let year = 2022;

options dlcreatedir;

libname out "mypath\&year";

and it works fine 🙂 
but I also want SAS to create a subfolder in the 

&year

-folder called 'data' and I thought I just could add: 

%let year = 2022;

options dlcreatedir;

libname out "mypath\&year\DATA";

But it dosen't work that way. I was thinking maybe do the 

options dlcreatedir;

libname out

 

twice. (like create the first folder, and then do the dlcreatedir once again, but I have a &year-macro variable so it dosen't make a good fit.

 

Anyone who can help me? 🙂 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
/*
Try function DCREATE()
--DCREATE(directory-name<,parent-directory>)
*/

%let year = 2022;

data _null_;
 new=dcreate("&year",'c:\temp\');
 new=dcreate("data",new);
 put new= ;
run;

View solution in original post

4 REPLIES 4
Patrick
Opal | Level 21

Using DLCREATEDIR allows you to create a folder under an existing parent folder. 

The code you've posted looks right and it's something that I've done already many times without ever having issues.

 

Below code will work if the absolute path d:\mypath already exists

%let year = 2022;
options dlcreatedir;
libname out "d:\mypath\&year";
libname out "d:\mypath\&year\data";
Ksharp
Super User
/*
Try function DCREATE()
--DCREATE(directory-name<,parent-directory>)
*/

%let year = 2022;

data _null_;
 new=dcreate("&year",'c:\temp\');
 new=dcreate("data",new);
 put new= ;
run;
cleokatt
Calcite | Level 5

@Ksharp how should the code look like if there was n subfolders in k?

Ksharp
Super User
/*
You should use N time for  DCREATE()
The following code would creata a path:
c:\temp\2022\data1\data2\data3\data4
*/

%let year = 2022;

data _null_;
 new=dcreate("&year",'c:\temp\');
 new=dcreate("data1",new);
 new=dcreate("data2",new);
 new=dcreate("data3",new);
 new=dcreate("data4",new);
 put new= ;
run;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 2313 views
  • 0 likes
  • 3 in conversation