BookmarkSubscribeRSS Feed
sasg
Calcite | Level 5

Hi,

     Running below macro on EG 4.2....What command should i use instead of mkdir.

   

%macro chk_dir(dir=);

%local rc fileref;

%let rc = %sysfunc(filename(fileref,&dir));

%if %sysfunc(fexist(&fileref)) %then

%put NOTE: The directory "&dir" exists;

%else

%do;

%sysexec md &dir;

%put %sysfunc(sysmsg()) The directory has been created.;

%end;

%let rc=%sysfunc(filename(fileref));

%mend chk_dir;

%chk_dir(dir=C:\test);

Thanks,

rk.

7 REPLIES 7
art297
Opal | Level 21

Not sure what your question is.  Are you looking for a SAS function?  The following post suggests using dcreate

http://communities.sas.com/message/13460

robby_beum
Quartz | Level 8

Are you saying that the mkdir command is not working for you?

%macro chk_dir(dir=);

%local rc fileref;

%let rc = %sysfunc(filename(fileref,&dir));

%if %sysfunc(fexist(&fileref)) %then

%put NOTE: The directory "&dir" exists;

%else

%do;

%sysexec mkdir "&dir" ;                                                    <======== What happens if you use this code instead?

%put %sysfunc(sysmsg()) The directory has been created.;

%end;

%let rc=%sysfunc(filename(fileref));

%mend chk_dir;

sasg
Calcite | Level 5

Hi Robby;

             Same issue with md and mkdir.

        

%chk_dir(dir=c:\test);

ERROR: Shell escape is not valid in this SAS session.

Thanks,

rk;

art297
Opal | Level 21

Did you try dcreate?

sasg
Calcite | Level 5

art,

       It worked with dcreate.

       Thanks a lot....but want to check,why it is not accepting spaces with mkdir.

Regards,

rk.

art297
Opal | Level 21

You might also want to take a look at: http://support.sas.com/kb/15/179.html

ScottBass
Rhodochrosite | Level 12

By default the EG workspace server is started with the -noxcmd option, meaning you cannot exit to the O/S to execute arbitrary code.  This is by design as a security feature.

If your server is a Windows server, you can make low level calls to the O/S via SASCBTBL.  See http://www.devenezia.com/downloads/sas/sascbtbl/.  AFAIK EG still allows this workaround to the -noxcmd option.

But yeah, IMO best practice is to use SAS code where possible.  This way your code is usually portable across O/S's.  So if dcreate works for you that would be the best solution.

HTH,

Scott


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 7 replies
  • 2618 views
  • 0 likes
  • 4 in conversation