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? 🙂
/*
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;
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";
/*
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;
@Ksharp how should the code look like if there was n subfolders in k?
/*
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.