BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
6 REPLIES 6
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Yes, you must create each level individually (as the DOC states, "create a directory").

Scott Barry
SBBWorks, Inc.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
deleted_user
Not applicable
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
Oleg_L
Obsidian | Level 7
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;
Oleg_L
Obsidian | Level 7
You can also use x command:

options noxwait;
x "md d:\work\dir_c";
deleted_user
Not applicable
Thanks for your help!

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 6 replies
  • 811 views
  • 0 likes
  • 3 in conversation