DATA Step, Macro, Functions and more

macro issue

Reply
Contributor
Posts: 42

macro issue

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.

PROC Star
Posts: 7,467

Re: macro issue

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

Contributor
Posts: 73

macro issue

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;

Contributor
Posts: 42

macro issue

Posted in reply to robby_beum

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;

PROC Star
Posts: 7,467

macro issue

Did you try dcreate?

Contributor
Posts: 42

macro issue

art,

       It worked with dcreate.

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

Regards,

rk.

PROC Star
Posts: 7,467

macro issue

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

Super Contributor
Posts: 387

Re: macro issue

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

Ask a Question
Discussion stats
  • 7 replies
  • 290 views
  • 0 likes
  • 4 in conversation