Hi there.
I am trying to create a folder for my output reports and I have tried all of these options:
%put NOTE: creating folder (%sysfunc(dcreate(Reports, ParentDir)));
%put NOTE: creating folder (%sysfunc(dcreate('Reports', 'ParentDir')));
%put NOTE: creating folder (%sysfunc(dcreate("Reports", "ParentDir")));A
At least, one of them should be correct but in all of the cases, the output is the same:
NOTE: creating folder ()
No output directory, no errors, no nothing. Just a blank string (and of course, the folder has not been created).
I am working in a pretty restricted environment (SAS 9.3) and I can't use either shell escape commands (like X or SysExec). Probably my problem is due to some other admin restriction but: no output at all? nothing? not an error or a warning?
Any clue?
Thanks in advance!
@Frn747 wrote:
Thank all for your suggestions.
I think that the key information and probably I don't explain it clearly enough is that I am trying to create the folder in my local machine, not in the server!
That is a fairly key distinction, EG is likely on your server and cannot see or access your local machine. So you cannot pass commands to your local machine in this manner, UNLESS you can select run locally in EG. Even then you cannot have local and server processes in the same process flow.
The documentation of dcreate says: "If the directory cannot be created, then DCREATE returns an empty string."
If you are using dcreate with %sysfunc, you need to use macro-variables, if "ParentDir" is a dataset-variable, don't use %sysfunc.
Thanks Andreas for your reply.
I already tried with macro-variables and with a data step with the same result:
%let newdir = 'Reports';
%let parentdir = 'C:\Users\Public\Documents\SAS Learning\';
%put NOTE: creating folder (%sysfunc(dcreate(&newdir, &parentdir)));
data _null_;
new = dcreate('Reports', 'C:\Users\Public\Documents\SAS Learning\');
put "NOTE: creating folder (" new ")";
run;
I have rights in that folder. I have no clues why the directory cannot be created!
@Frn747 wrote:
I have rights in that folder.
Did you check that by logging on to the SAS server and testing md from the commandline?
Then from where do you take it that you have the necessary permissions, or that the path exists at all?
Don't put quotes into macro variables, unless you need the quotes in the strings you are generating.
Make sure that the parent directory exists on the machine where SAS is running. Try FILEEXIST(). And is a directory and not a normal file try DOPEN().
@Frn747 wrote:
Thanks Andreas for your reply.
I already tried with macro-variables and with a data step with the same result:
%let newdir = 'Reports'; %let parentdir = 'C:\Users\Public\Documents\SAS Learning\'; %put NOTE: creating folder (%sysfunc(dcreate(&newdir, &parentdir))); data _null_; new = dcreate('Reports', 'C:\Users\Public\Documents\SAS Learning\'); put "NOTE: creating folder (" new ")"; run;
I have rights in that folder. I have no clues why the directory cannot be created!
The first try won't work due to using quoted strings, as @Tom already said. The data-null-step should work, if the path C:\Users\Public\Documents\SAS Learning\
exists on the server. The blank in "SAS Learning" could cause trouble, that's why i hardly every use blanks in filenames or directory-names.
Thank all for your suggestions.
I think that the key information and probably I don't explain it clearly enough is that I am trying to create the folder in my local machine, not in the server!
I already have the reports generated in the server but I need to download them to my local machine. I am using the "Copy Files" add-in but it needs the folder to exist and I can't figure out how to ensure the folder exist and if not, create it.
@Frn747 wrote:
Thank all for your suggestions.
I think that the key information and probably I don't explain it clearly enough is that I am trying to create the folder in my local machine, not in the server!
I already have the reports generated in the server but I need to download them to my local machine. I am using the "Copy Files" add-in but it needs the folder to exist and I can't figure out how to ensure the folder exist and if not, create it.
Then you need to edit the code of the Copy Files add-in. Which is NOT SAS code.
@Frn747 wrote:
Thank all for your suggestions.
I think that the key information and probably I don't explain it clearly enough is that I am trying to create the folder in my local machine, not in the server!
That is a fairly key distinction, EG is likely on your server and cannot see or access your local machine. So you cannot pass commands to your local machine in this manner, UNLESS you can select run locally in EG. Even then you cannot have local and server processes in the same process flow.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.