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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 809 views
  • 0 likes
  • 3 in conversation