Desktop productivity for business analysts and programmers

I would need create a directory with mmddyy format in one location by using x command.

Reply
Occasional Contributor
Posts: 9

I would need create a directory with mmddyy format in one location by using x command.

1)I would need create one directory like 24042018(directory) by using X command

for example : 'x mkdir /data/file/data_folder';

when ever we run that code it will create current datefolder

 

2)Directories should maintain only week folders remaining folder should delete through sas program

 

Really appreciate your help on this

 

Super User
Posts: 24,004

Re: I would need create a directory with mmddyy format in one location by using x command.

Why XCMD? Can you use DCREATE()? Or the LIBNAME trick with the DLCREATEDIR option enabled.

https://blogs.sas.com/content/sasdummy/2013/07/02/use-dlcreatedir-to-create-folders/

 

There's also FDELETE() to delete the folders you don't want.

 

 

Occasional Contributor
Posts: 9

Re: I would need create a directory with mmddyy format in one location by using x command.

Hi Thanks for your reply but we are using unix environment .All the folders are in unix boxes.that is why I am using X commands

but I would need create directory with current dateformat for example the if I execute the sas code today it should create folder like 24042018 in some directory

Really appreciate your help 

Super User
Posts: 24,004

Re: I would need create a directory with mmddyy format in one location by using x command.

Not sure why you still can't use DCREATE() or LIBNAME. This is the idea below. 

 

data _null_;

path_to_folder = '/folders/myfolders/';
date_char = put(today, yymmdd10.);
folder_name = catx("_", 'folder', date_char);

y = dcreate(folder_name, path_to_folder);

run;


To check for the existence of the other folder you can use FEXIST and then FDELETE. You didn't specify how the naming is managed but it should be relatively straightforward if you have a structured process. 

 


@Pavan4 wrote:

Hi Thanks for your reply but we are using unix environment .All the folders are in unix boxes.that is why I am using X commands

but I would need create directory with current dateformat for example the if I execute the sas code today it should create folder like 24042018 in some directory

Really appreciate your help 


 If you have to use X commands, you need to find the Unix commands which is best done on a unix forum, and then you pass them to the system using %SYSEXEC, CALL SYSTEM, or X statements. 

 

In that case, I'd test the commands on the unix side first as well and then move the commands back to SAS after they're fully tested, otherwise you have more room for error.

Ask a Question
Discussion stats
  • 3 replies
  • 124 views
  • 1 like
  • 2 in conversation