Help using Base SAS procedures

Creating directory structure

Reply
N/A
Posts: 0

Creating directory structure

Hi,

I need to create a directory structure through my SAS program.

I was looking at DCREATE function.So, suppose I've to create a directory structure C:\DAG\SAS\Tests, from what I understand from the documentation is, I have to iteratively create each of the folders DAG,SAS and then Tests with 3 separate calls for DCREATE. Is this correct?
Or, if there is any other function that takes the whole path C:\DAG\SAS\Tests and creates the whole directory structure, can someone please point me to that?

Thanks,
Neel
Super Contributor
Super Contributor
Posts: 3,174

Re: Creating directory structure

Posted in reply to deleted_user
Yes, you must create each level individually (as the DOC states, "create a directory").

Scott Barry
SBBWorks, Inc.
Super Contributor
Super Contributor
Posts: 3,174

Re: Creating directory structure

You have some other options to consider - refer to this tech document from the SAS support http://support.sas.com/ website, which I found using the website's SEARCH command:

http://support.sas.com/techsup/technote/ts353.html


Also, the "pipe" engine of FILENAME is mentioned in this SAS conference paper:

Check out These Pipes: Using Microsoft Windows Commands from SAS®
Brian Varney, COMSYS Business Analytics Practice, Kalamazoo, Michigan
http://www2.sas.com/proceedings/forum2008/092-2008.pdf


Scott Barry
SBBWorks, Inc.
N/A
Posts: 0

Re: Creating directory structure

Thanks a lot!

I found the paper with information about pipe helpful.

I got it working.

My macro is

-------------------------------------------------------------
%macro createFolder(folderName);

/* Executing windows command */
filename pipmkdir pipe "mkdir &folderName";
data _null_;
infile pipmkdir;

%mend;

--------------------------------------------------------------------

Though, with known issue of mkdir, when there is a space in a folder name,
say for example C:\DAG\Unit Test, then the mkdir will not work as expected.
But putting double quotes around the folder name will work like mkdir "C:\DAG\Unit Test"


I was not able to figure out how to have double quotes around the folderName parameter in the macro..

I want to change the line in macro
filename pipmkdir pipe "mkdir &folderName";

to
filename pipmkdir pipe "mkdir "&folderName" "; (I tried this, didn't work)

Is there any escape character for having double quotes in a string?

Thanks,
Neel
Regular Contributor
Posts: 151

Re: Creating directory structure

Posted in reply to deleted_user
Hi!
You can use this macro (if you use Windows).

%MACRO MD(DIR=d:\bd_comp\data\2005\m6);
%LET COUNT=0;
%LET DLM=\;
%IF %SUBSTR(&DIR,%LENGTH(&DIR),1) NE &DLM %THEN %DO;
%LET DIR=&DIR&DLM;
%END;
%DO J=1 %TO %LENGTH(&DIR);
%IF %SUBSTR(&DIR,&J,1)=&DLM %THEN %DO;
%LET COUNT=%EVAL(&COUNT+1);
%END; %END;
%LET DRIVE=%SUBSTR(&DIR,1,3);
%LET LEVEL=&DRIVE;
%DO I=2 %TO &COUNT;
%LET WORD=%SCAN(&DIR,&I,&DLM);
%LET LNEW=&LEVEL&WORD&DLM;
data _null_;
rc=filename('newdir',"&lnew");
c=dopen('newdir');
if c=0 then new=dcreate("&word","&level");
run;
%LET LEVEL=&LNEW;
%END;
%MEND MD;
Regular Contributor
Posts: 151

Re: Creating directory structure

You can also use x command:

options noxwait;
x "md d:\work\dir_c";
N/A
Posts: 0

Re: Creating directory structure

Thanks for your help!
Ask a Question
Discussion stats
  • 6 replies
  • 180 views
  • 0 likes
  • 3 in conversation