BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
djbateman
Lapis Lazuli | Level 10

I don't know if this is even possible, but I'm just going to throw this question out there.

I was wondering if SAS has the ability to create folders?  For example, suppose I automatically run code every week that generates a host of output files.  Suppose I output them in C:\SAS\Reports, but I want to have a new subfolder with the date each time the reports are generated so that this week they are output to C:\SAS\Reports\2015-02-20 and next week they are output to C:\SAS\Reports\2015-02-27, and so on.  This way, I don't have to manually create a new folder each time and move all the files from one place to another.

Is this possible?

1 ACCEPTED SOLUTION

Accepted Solutions
7 REPLIES 7
Haikuo
Onyx | Level 15

DCREATE function.

Jaheuk
Obsidian | Level 7
%MACRO check_dir(dir=) ;
      OPTIONS NOXWAIT ;
     
%LOCAL rc fileref ;
     
%LET rc = %SYSFUNC(FILENAME(fileref,&dir)) ;
     
%IF %SYSFUNC(FEXIST(&fileref)) %THEN
         
%PUT NOTE: Directory &dir does already exist. ;
     
%ELSE
         
%DO ;
             
%SYSEXEC MD &dir ;
             
%PUT %SYSFUNC(SYSMSG()) Directory is created. ;
         
%END ;
     
%LET rc=%SYSFUNC(FILENAME(fileref)) ;
%mend check_dir ;

%
check_dir(dir = c:\temp\DATA );
Haikuo
Onyx | Level 15

At the risk of being obnoxious, me still think DCREAT is the better option. Let SAS to worry about OS. You went a great deal of using Macro, you can host your OS independent directory into Macro variable, so it even makes more sense for you to NOT use 'MD'.   What if later on your system is being migrated to Linux (or any other OS that SAS is running on)? switch it to 'mkdir'?

Just my2cents,

Haikuo

Kurt_Bremser
Super User

Since one already has to consider the underlying OS's naming syntax when using any of the methods, I don't see the possible migration as a major argument. Personally, I would use the filename pipe and data _null_ step method to get a comprehensive log in case something went wrong.

In a case where the "create a directory" function is done via macro, only one macro needs to be adapted to a new platform, but all calls need to be checked for syntax anyway (a "C:\" in a UNIX path name may have interesting consequences)

RW9
Diamond | Level 26 RW9
Diamond | Level 26

I would agree with you Hai.kuo, for the reasons you have given, and also that piping commands out to system sometimes is blocked by admin, and if it doesn't work - i.e. macro does not work correctly, you do run the risk of removing things unintentionally, or creating loads of unwanted folders etc. temporary areas.

rcwright
Calcite | Level 5

At the risk of appearing vain, here's a sample I submitted a few years ago - https://communities.sas.com/thread/71369

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2289 views
  • 1 like
  • 6 in conversation