Desktop productivity for business analysts and programmers

FileName and using winapi to create a windows directory.

Reply
Occasional Contributor
Posts: 15

FileName and using winapi to create a windows directory.

23         /*** sample code to create a directory and move a file to that directory ***;*/
24         %let from_file=%str('z:\Test.txt');
25         %let to_file=%str('z:\test\test.txt');
26         %let new_directory=%str('z:\test\');
27         
28         Filename SASCBTBL "V:\CORPDATA72\sas_eor\RENO_HMS\Library\SASCBTBl.TXT";
29         
30         
31         DATA _NULL_;
32         From_file=&from_file;
33         To_file=&to_file;
34         
35         New_directory=&new_directory;
36         Rc1=modulen('*i','CreateDirectoryA',new_directory,0);
37         /* Since the CreateDirectory function returns a Boolean value,;
38         * the MODULEN function is used.;
39         * 0 makes sure the security settings are the default settings in windows,;
40         * change at your own risk;*/
41         Rc2=modulen('*i','MoveFileA',from_file,to_file);
42         /* Since the MoveFile function returns a Boolean value,;
43         * the MODULEN function is used.;*/
44         %Put rc1= rc2=;
rc1= rc2=
45         Run;

WARNING: SASCBTBL file could not be opened.
ERROR: Module CreateDirectoryA could not be loaded.

So I have a need to create new directories within the Windows environment using SAS EG.   Due to admin rules the various uses of external OS command features are not available. (i.e. x mkdir -p.., rc = system('mkdir...)  

 

 

Something that may be available to me is the use of the module function for which I have found several examples and have tried to convert to use.

 

While using the attached code the statement: Filename SASCBTBL "V:\CORPDATA72\sas_eor\RENO_HMS\Library\SASCBTBl.TXT";

fails with the following error: WARNING: SASCBTBL file could not be opened.

 

I have altered single and double quotes as well as file name length and extension.

 

Any suggestions?

Regular Contributor
Posts: 227

Re: FileName and using winapi to create a windows directory.

Posted in reply to RAW_newbie

options dlcreatedir;

 

That'll create the directory for you (only one level deep at a time, though).

Super User
Posts: 4,013

Re: FileName and using winapi to create a windows directory.

Posted in reply to RAW_newbie
Occasional Contributor
Posts: 15

Re: FileName and using winapi to create a windows directory.

I tried the dcreate option but was only successful in creating a new directory on the SAS server not on the windows server.  I do not recall or captured an error message being generated.  Log file may have returned "not successful due to security" on a windows directory I created.

 

Super User
Posts: 4,013

Re: FileName and using winapi to create a windows directory.

Posted in reply to RAW_newbie

You will need to work with your IT / SAS administrators regarding the correct permissions for this, particularly if you are using single signon using Windows Authentication to access SAS. It should work once the permissions are sorted.  

Occasional Contributor
Posts: 15

Re: FileName and using winapi to create a windows directory.

I have requests in for this and will see where it goes.

Respected Advisor
Posts: 4,779

Re: FileName and using winapi to create a windows directory.

Posted in reply to RAW_newbie

@RAW_newbie

"but was only successful in creating a new directory on the SAS server not on the windows server"

What do you mean by that? The "SAS Server" could be running under Windows (a "windows server"). 

 

You're executing your scripts on the SAS Server (the compute tier) which is a process running on some server (Windows, Unix,..). The paths available to you are the ones available from the SAS Server side (the "box" SAS Server is executing from).

 

You're using Windows pathnames in your code. To do so these paths would need to be mapped to the Server ("the box") where the SAS Server executes. Normally that's not the case unless you've got a local SAS installation.

 

So first thing you need to figure out: Can you access these paths at all (i.e. using UNC paths) from the Server side or are they only available to your local desktop environment?

Super User
Super User
Posts: 8,264

Re: FileName and using winapi to create a windows directory.

Posted in reply to RAW_newbie

@RAW_newbie wrote:

I tried the dcreate option but was only successful in creating a new directory on the SAS server not on the windows server.  I do not recall or captured an error message being generated.  Log file may have returned "not successful due to security" on a windows directory I created.

 


What does that mean?  The SAS code can only run commands on the machine that is running the SAS code. 

 

If you want the SAS process to create a directory then it needs to have write access to the parent directory so it can make the new directory.

Ask a Question
Discussion stats
  • 7 replies
  • 211 views
  • 0 likes
  • 5 in conversation