BookmarkSubscribeRSS Feed
Yennie
Calcite | Level 5
Hi there,

I am currently wanting to save a sas dataset into my own drive as a csv file. And I have to do this every month for my department. Therefore, wondering if there is any sas code that can help to create a new folder in my drive automatically??

I have the below script... (part of it...)

%Let dir = K:\\int\Collaborate\PI\;
%Let folder_name = abc_folder; ---> This is the extra folder that I am referring to. I am wanting to create this folder every month, however I am wanting to utilise sas to help me create this extra folder automatically instead of having to get someone (while i am away for annual leave) to go into our network drive to create this folder manually so that just by a press of button they can run the script and that's all it does.

%Let csvname = abc.csv;

Proc Export
Data = Criteria
Outfile = "&Dir&folder_name&csvname"
DBMS = CSV Replace;
Run;

hoping someone can help.

Cheers!
Yennie
7 REPLIES 7
Cynthia_sas
SAS Super FREQ
Hi:
You can use the X command to create directories on your system (using operating system commands, such as MKDIR) or you can use the DCREATE function from within a SAS program. Either the SAS companion for your operating system (in the documentation) will have examples or you can open a track with Tech Support for more help about automatic directory creation using a program.

Or you could create an operating system script or command file and execute your SAS program (your .SAS file) from within that script (such as a .BAT or .CMD file). Again, the SAS Companion for your operating system will have examples of how to submit a batch SAS program from within an operating system script or command file.

cynthia
Yennie
Calcite | Level 5
Hi cynthia,

I used this command

X mkdir 'K:\Monthly BackUp\2010\ABC\"'; where ABC is my extra folder ?

However, I had this error on my SAS

REMOTE(SASAP1): ..
REMOTE(SASAP1): .: The file access permissions do not allow the specified action.

Does this means i will have to speak to my sas support helpdesk guys?
Cynthia_sas
SAS Super FREQ
hi:
When I use the mkdir command on my Windows system, I use this syntax (note that the operating system command is INSIDE the quotes):
[pre]
options noxwait noxsync;
x 'md c:\temp\outfile';
[/pre]

However, you might still receive file access permission errors which would mean that you'd have to discuss the issue, and/or have permissions changed by your security/system/admin folks.

cynthia
Yennie
Calcite | Level 5
Hey Cynthia,

works amazingly. your awesome! 🙂

cheers!!!
Oleg_L
Obsidian | Level 7
Greetings.

This macro creates a directory.

%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;


Regards,
Oleg.
Oleg_L
Obsidian | Level 7
You can also use MD Windows command.

systask command
"md ""d:\work\cc 2009"""
wait taskname="md";

Regards,
Oleg.
Olga3
Calcite | Level 5

Thank you Oleg! It worked for me. Very helpful.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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