Help using Base SAS procedures

Is it possible to use sas to create a new folder in my own drive ?

Reply
Frequent Contributor
Posts: 78

Is it possible to use sas to create a new folder in my own drive ?

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
SAS Super FREQ
Posts: 8,743

Re: Is it possible to use sas to create a new folder in my own drive ?

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
Frequent Contributor
Posts: 78

Re: Is it possible to use sas to create a new folder in my own drive ?

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?
SAS Super FREQ
Posts: 8,743

Re: Is it possible to use sas to create a new folder in my own drive ?

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
Frequent Contributor
Posts: 78

Re: Is it possible to use sas to create a new folder in my own drive ?

Hey Cynthia,

works amazingly. your awesome! Smiley Happy

cheers!!!
Regular Contributor
Posts: 151

Re: Is it possible to use sas to create a new folder in my own drive ?

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.
Regular Contributor
Posts: 151

Re: Is it possible to use sas to create a new folder in my own drive ?

You can also use MD Windows command.

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

Regards,
Oleg.
Ask a Question
Discussion stats
  • 6 replies
  • 441 views
  • 0 likes
  • 3 in conversation