Using SAS and mkdir to create a directory structure in windows

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.

+3
source share
4 answers

You need to use the -p mkdir option, which will create all subfolders

i.e.

x mkdir -p "c: \ newdirectory \ level 1 \ level 2";

+1
source

I am also on WinXP using SAS 9.3 TS1M1. The following works are advertised for me:

 122 options noxwait; 123 data _null_; 124 rc = system('mkdir \\W98052442n3m1\public\x\y\z'); 125 put rc=; 126 run; rc=0 NOTE: DATA statement used (Total process time): real time 1.68 seconds cpu time 0.03 seconds 

This is my actual log file; "public" is the Windows shared folder on this network PC, and the entire path has been created. Perhaps using the SYSTEM function did the trick. I have never used the X command.

+1
source

You need to specify your x commands, for example.

 x 'mkdir "c:\this\that\something else"' ; 

Also, I never had problems using UNC paths, for example.

 x "\\server.domain\share\runthis.exe" ; 
+1
source

Everything seems to be working fine while the dos window remains open. You may need the XSYNC option. I am using 9.3 TS1M1 64 bit in VMWARE on MAC:

 options xwait xsync; x mkdir c:\newdirectory; 
0
source

Source: https://habr.com/ru/post/949780/


All Articles