title: Using SAS and mkdir to create a directory structure in windows
body: <p>I want to create a directory structure in Windows from within SAS.  Preferably using a method that will allow me to specify a UNC naming convention such as:</p>
  
  <pre><code>\\computername\downloads\x\y\z
  </code></pre>
  
  <p>I have seen many examples for SAS on the web using the DOS <code>mkdir</code> command called via <code>%sysexec()</code> or the <code>x</code>command.  The nice thing about the mkdir command is that it will create any intermediate folders if they also don't exist.  I successfully tested the below commands from the prompt and it behaved as expected (quoting does not seem to matter as I have no spaces in my path names):</p>
  
  <pre><code>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"
  </code></pre>
  
  <p>The following run fine from SAS:</p>
  
  <pre><code>x mkdir d:\x;
  x 'mkdir d:\y';
  x 'mkdir "d:\z"';
  x mkdir \\computername\downloads\x;
  x 'mkdir \\computername\downloads\y';
  </code></pre>
  
  <p>But these do not work when run from SAS,eg:</p>
  
  <pre><code>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;
  </code></pre>
  
  <p>It does not work.  Not only this but the window closes immediately even though I have <code>options xwait</code> specified so there is no opportunity to see any ERROR messages.  I have tried all methods with both the UNC path and a drive letter path, ie. <code>D:\downloads\x\y\z</code>.</p>
  
  <p>If I look at the error messages being returned by the OS:</p>
  
  <pre><code>%put %sysfunc(sysrc()) %sysfunc(sysmsg());
  </code></pre>
  
  <p>I get the following:</p>
  
  <pre><code>-20006 WARNING: Physical file does not exist, d:\downloads\x\x\x.
  </code></pre>
  
  <p>Looking at the documentation for the <code>mkdir</code> command it appears that it only supports creating intermediate folders when 'command extensions' are enabled.  This can be achieved with adding the <code>/E:ON</code> to <code>cmd.exe</code>.  I've tried changing my code to use:</p>
  
  <pre><code>cmd.exe /c /E:ON mkdir "\\computername\downloads\x\y\z"
  </code></pre>
  
  <p>And still no luck!</p>
  
  <p>Can anyone tell me why everyone else on the internet seems to be able to get this working from within SAS except for me?  Again, it works fine from a DOS prompt - just not from within SAS.</p>
  
  <p>I'd prefer an answer that specifically address this issue (I know there are other solutions that use multiple steps or <code>dcreate()</code>).</p>
  
  <p>I'm running WinXP 32Bit, SAS 9.3 TS1M2.  Thanks.</p>