Hi,
I have a macro list with the names of 3 comapanies: A,B and C, and the variable for the compnies is "company"
for each company I would like to create a folder on my computer, and I use the following code:
data _null_;
do while &company ne ;
x "mkdir c:\test\&company";
end;
run;
On the other hand when I just do:
x "mkdir c:\test\A";
x "mkdir c:\test\B";
x "mkdir c:\test\C";
I get the 3 folders as wanted, so it seems that there is a problem with my iteration.
Thank you!
*Maybe you can skip the macro variable step,
assuming you create it from a list of companies in a dataset;
data have;
input company $;
cards;
A
B
C
;
run;
data new_dirs;
set have;
new_dir= dcreate(company, "C:\test\");
run;
Your loop is specified incorrectly.
You can use dcreate as well, fyi.
What does your macro variable look like, resolve to? I'm not sure how you expect it to loop.
*Maybe you can skip the macro variable step,
assuming you create it from a list of companies in a dataset;
data have;
input company $;
cards;
A
B
C
;
run;
data new_dirs;
set have;
new_dir= dcreate(company, "C:\test\");
run;
Hi Reeza,
thnka sfor the code, I ran it but the column "new_dir" that it created was empty (and no new folders...).
Initially I had a data set "test" with many lines per company, then I extracted the unique comany names witht he following code:
proc sql noprint;
create table companies as select distinct company into: cmlst separated by ' ' from test;
quit;
And then I did the my code...
Thanks!
Post post your code and log.
proc sql noprint;
create table companies as select distinct company from test;
quit;
Data want;
Set companies;
New_dir=Dcreate(company, 'C:\test\');
Run;
Also check your folder to see if they're created.
Hi Reeza,
I am getting very weired results:
Once I tried your sample code when the 3 companies were written in a data step and actually got the 3 folders!!! (and the paths to the directories were included in the new_dir).
Then I wanted to do the same thing with my data but didn't get anything (and the new_dir is empty), and when wanted to re do your sample code also didn't get anything! There is no error message whatsoever.
???
Thanks!
No, there is no,error message. Read the doc regarding the function.
If your having issues you can use call system instead and build file path using CAT functions.
If the folder already exists they won't get overwritten.
Hi Reeza,
sorry for being so confusing but now it works all the time!!!
Its just that I realized that the directory "test" must already exist in order for the other directories to be put into it.
Last time when your sample code worked and I wanted to redo it on my company data I actually deleted the "test" directory (which somehow I had from previous attempts) in order to see how the code fully works, and that's when I wasn't getting anything becasue from what now I understand the function DECREATE must be given a parent directory since it doesn't create the "full path" but rather only the "end of the line" directory.
Thank you for your help and for making me discover DECREATE!!!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.