BookmarkSubscribeRSS Feed
RAW_newbie
Obsidian | Level 7
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?

7 REPLIES 7
tomrvincent
Rhodochrosite | Level 12

options dlcreatedir;

 

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

RAW_newbie
Obsidian | Level 7

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.

 

SASKiwi
PROC Star

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.  

RAW_newbie
Obsidian | Level 7

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

Patrick
Opal | Level 21

@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?

Tom
Super User Tom
Super User

@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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1184 views
  • 0 likes
  • 5 in conversation