*
;
/*
Dynamically allocating directory in Windows

>>  The problem:
>> I have a SAS data set that contains a variable that
>> contains a directory to be allocated i.e.
>> dirn='c:\sas\yields\var1\var2\var3';
>> How can I use this variable to dynamically allocate the directory
>> structure. I tried an X command with with a macro var created from the
>> variable but DOS will only allocate on level at a time. Any help
>> would be greatly appreciated. NOTE: this code will also need to be
>> ported to other operating systems such as VAX and UNIX.
>>
>> Thanks in advance for your help

    Here is a way

    Test the makedir macro... the XWAIT option is useful for watching the
    results of the system command.  You probably want to change it to
    NOXWAIT once you have it working....

   "Jim Carter, SCT Corporation" 
 */
%macro makedir( type, dname );
   %if &type eq 'PC' %then %do;
/*****************************************************************************
        For PCs: Create a batch file full of MD commands - one for each
        sub-directory in the path.  Then run this batch file with one
        system command.
*****************************************************************************/
        data _null_;
           dirname = &dname;
           dircnt = 1;
           delim = '\';
           dir = scan(dirname,dircnt,delim);
           file 'c:\makedirs.bat';
           ndir = dir;
           makedir = 'md';
           do while (dir ne ' ');
                dircnt = dircnt+1;
                dir = scan(dirname,dircnt,delim);
                if dir ne ' ' then ndir = trim(ndir) || delim || dir;
                put makedir ' ' ndir;
           end;
        run;
        data _null_;
           length sysstr $ 20;
           sysstr = 'c:\makedirs';
           call system(sysstr);
        run;
   %end;
   %else %if &type eq 'VMS' %then %do;
/*****************************************************************************
        For VMS: A single CREATE/DIR" command should do it.
*****************************************************************************/
        data _null_;
           length sysstr $ 200;
           sysstr = 'create/dir ' || &dname;
           call system(sysstr);
        run;
   %end;
   %else %if &type eq 'Unix' %then %do;
/*****************************************************************************
        For Unix: A single "mkdir" command with the "-p" option should do it.
*****************************************************************************/
        data _null_;
           length sysstr $ 200;
           sysstr = 'mkdir -p' || &dname;
           call system(sysstr);
        run;
   %end;
%mend;

/*  Test the makedir macro... the XWAIT option is useful for watching the
    results of the system command.  You probably want to change it to
    NOXWAIT once you have it working.... */

options xwait;   /* Have SAS prompt for a  after completing... */

data _null_;
   %makedir( 'PC', 'C:\JIM1\test1\test2\test3' )
   %makedir( 'VMS', '[.JIM1.JIM2.JIM3]' )
   %makedir( 'Unix', './dir1/dir2/di3/dir4' )
run;

*
;