I want to create a directory structure on Windows from SAS. It is preferable to use a method that allows me to specify a UNC naming convention, such as:
\\computername\downloads\x\y\z
I have seen many examples for SAS on the Internet using the mkdir DOS command called through %sysexec() or the x command. The best part of the mkdir command is that it will create any staging folders if they also don't exist. I successfully tested the following commands from the prompt and behaved as expected (quoting doesn't seem to matter, since I don't have spaces in the path names):
mkdir \\computername\downloads\x\y\z mkdir d:\y mkdir d:\y\y mkdir "d:\z" mkdir "d:\z\z" mkdir \\computername\downloads\z\z\z mkdir "\\computername\downloads\z\z\z"
The following script from SAS:
x mkdir d:\x; x 'mkdir d:\y'; x 'mkdir "d:\z"'; x mkdir \\computername\downloads\x; x 'mkdir \\computername\downloads\y';
But they do not work when starting from SAS, for example:
x mkdir d:\x\x; x 'mkdir d:\y\y'; x 'mkdir "d:\z\z"'; x mkdir \\computername\downloads\x\y\z ; x 'mkdir "\\computername\downloads\z"'; ** OR **; %sysexec mkdir "\\computername\downloads\x\y\z "; ** OR **; filename mkdir pipe "mkdir \\computername\downloads\x\y\z"; data _null_; input mkdir; put infile; run;
This does not work. Not only that, but the window closes immediately, even if I have options xwait , so there is no way to see ERROR messages. I tried all the methods with both the UNC contour and the letter on the disk, i.e. D:\downloads\x\y\z .
If I look at the error messages returned by the OS:
%put %sysfunc(sysrc()) %sysfunc(sysmsg());
I get the following:
-20006 WARNING: Physical file does not exist, d:\downloads\x\x\x.
Looking at the documentation for the mkdir command, it shows that it only supports the creation of staging folders when "command extensions" are activated. This can be achieved by adding /E:ON to cmd.exe . I tried changing my code to use:
cmd.exe /c /E:ON mkdir "\\computername\downloads\x\y\z"
And still no luck!
Can someone tell me why everyone else on the Internet seems to be able to get this job from SAS except me? Again, it works great with the DOS hint - just not inside SAS.
I would prefer an answer that specifically solves this problem (I know there are other solutions that use multiple steps or dcreate() ).
I am running WinXP 32Bit, SAS 9.3 TS1M2. Thanks.