BookmarkSubscribeRSS Feed
alexandravieira
Fluorite | Level 6

I'm trying to write a program to create a folder in the sas studio folder structure. So far I've tried DCREATE and options DLCREATEDIR without success:

 

data _null;
newdir=dcreate('newsubfolder','/path/that/exists');
run;

this resulted in:

 

NOTE: The data set WORK._NULL has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

But no folder was created in '/path/that/exists'.

 

Then I tried:

options DLCREATEDIR;
libname newdir '/path/that/exists/newsubfolder';

this got me an error:

ERROR: Create of library NEWDIR failed.
ERROR: Error in the LIBNAME statement.

Is there a way I can do this?

I should say I do not have CAS available in my sas viya implementation, not sure if this is relevant but it has limited me in many ways before so maybe this is another one.

 

 

 

 

8 REPLIES 8
JackHamilton
Lapis Lazuli | Level 10

Are you sure you have write access to create a new directory?  

 

What is the value of newdir in your first step? 

 

And why are you creating a data set named "_NULL"?

 

There's a collection of tested macros at https://github.com/sasjs/core , with documentation at https://core.sasjs.io/files.html .  mf_mkdir.sas creates a directory.  You might try using that macro to see if you get a better error message.

 

 

alexandravieira
Fluorite | Level 6

Thanks for your answer.

Are you sure you have write access to create a new directory? - yes I can create folders manually

What is the value of newdir in your first step? - it's null

And why are you creating a data set named "_NULL"? - it was meant to be _null_ 

As for the mf_mkdir macro, it does not help me, since it uses dcreate just like I was using it. I believe the problem is that "path/that/exists" is not the right path, as in, it doesn't start at the beginning of the root.

ballardw
Super User

If your "path/that/exists" does not start at a Drive (windows) or disk mount point (linux) then the attempt was likely using a relative to where SAS executed.

Since you cleverly did not provide any actual path or LOG (HINT) showing the error we can't point to a specific place your code is wrong.

 

Then there is the bit about the path has to be in terms of the system executing code. If you are running SAS in a server version then it is very likely that the server would not see a path local to your computer.

 

You also will need write permissions.

alexandravieira
Fluorite | Level 6

Thanks for your answer.

I did provide the log.

I cannot specify what exactly "path/that/exists" is because I'm not allowed to. It does not, however, start at the disk mount, so that is probably the reason. I can only see the folders in my sas studio explorer and don't know how to extract the server path for them in SAS Studio as I can in SAS EG for example.

I do have writing permissions to that folder as I can create the subfolder manually.

ballardw
Super User

So you can't actually show the real path.

Okay.

Then from the log type in actual path over the actual one that LOOKS the same.

 

Personal opinion: code should NEVER contain anything sensitive. If data set names or paths are sensitive then the names are wrong to begin with.

 

Or get permission from whoever won't allow such to go to SAS Tech support and discuss it with them.

Tom
Super User Tom
Super User

If you have an existing libref or fileref that is pointing to the top node of you folders you can use that to construct your new path.

data _null_;
   length topnode target $256 ;
   topnode=pathname('mylib');
   target=catx('/',topnode,'subdir');
   rc=createdir(target);
run;

If you are really using CAS server instead of running base SAs then I think files work differently there and that might be the issue are having.

JackHamilton
Lapis Lazuli | Level 10

You provided little snippets out of a log, which is not quite the same thing.  Seeing more context might help in seeing what the problem is.

Sajid01
Meteorite | Level 14

"I do have writing permissions to that folder as I can create the subfolder manually."
That means you must have an idea of the absolute path to the location where you want to create the folder.
I suggest you use the absolute path in your statement. 
data _null_;
newdir=dcreate('newsubfolder','Absolute_path_of_parent_folder_');
run;

(using data _null creates a dataset _null. recommend using  _NULL_ instead).
If you are not able to create the subfolder after this change, then check if the id you are using to sign in to the SAS Studio and that to sign in to the server locations are same.
The workspace server executes the program and uses the login credentials. From the log snippet you have in your question, the user id that workspace session is using does not have the necessary authorization.
If workspace server logs are enabled, there may be mention of the cause.


 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 4624 views
  • 2 likes
  • 5 in conversation