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.

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!

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.

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
  • 1453 views
  • 0 likes
  • 4 in conversation