BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Tom
Super User Tom
Super User

Take out the second MONTH() function, MONNAME format applies to real date, not a month number. It was getting the month for 02JAN1960.

To figure out what date it was last month use the INTNX function.

vomer
Obsidian | Level 7

Sorry I am a bit confused... taking it out caused an error...

Also where/how does the INTNX go? Could you please provide the code.. sorry I am very new to SAS.

Tom
Super User Tom
Super User

This will get todays date. Get a date in the previous month.  Build the directory names into variables. Then call the DCREATE() function to make the directories.

I put the parent directory into a variable so that I can use it two places without having to type it twice.

The PUT statement will let you see the directory names that it generated and the result of the DCREATE function.

data _null_;

  rootdir='U:\Software\';

  today=today();

  lastmonth=intnx('month',today,-1);

  dir1=catx(' ',put(month(lastmonth),z2.),'-',put(lastmonth,monname3.),year(lastmonth));

  dir2=catx(' ',put(month(today),z2.),'-',put(today,monname3.),year(today));

newdir1=dcreate(dir1,rootdir);

  newdir2=dcreate(dir2,rootdir);

  put (rootdir dir1 newdir1 dir2 newdir2) (=/);

run;

vomer
Obsidian | Level 7

Tom, that is amazing! I wil give this a try soon.

One final question (I promise) : After the directory (01 - Jan 2012) is made using the script your provided, is there any way I can also add a sub-directory under the newly created 01 - Jan 2012 folder?

I used an "x" command but it did not work and got stuck on the command line window.

Linlin
Lapis Lazuli | Level 10

Hi,

I tried Tom's code. It works great! I was able to create a sub_directory "test" under the newly created "01 -jan 2012 "folder.

data _null_;

  rootdir='c:\temp\';

  today=today();

  lastmonth=intnx('month',today,-1);

  dir1=catx(' ',put(month(lastmonth),z2.),'-',put(lastmonth,monname3.),year(lastmonth));

  dir2=catx(' ',put(month(today),z2.),'-',put(today,monname3.),year(today));

  dir3='test'; /* Iadded */

  newdir1=dcreate(dir1,rootdir);

  newdir3=dcreate(dir3,newdir1); /* i added*/

  newdir2=dcreate(dir2,rootdir);

  put (rootdir dir1 newdir1 dir2 newdir2 dir3 newdir3) (=/);

run;

from log file:

rootdir=c:\temp\

dir1=01 - Jan 2012

newdir1=c:\temp\01 - Jan 2012

dir2=02 - Feb 2012

newdir2=c:\temp\02 - Feb 2012

dir3=test

newdir3=c:\temp\01 - Jan 2012\test

NOTE: DATA statement used (Total process time):

      real time           0.03 seconds

      cpu time            0.01 seconds

Message was edited by: Linlin

vomer
Obsidian | Level 7

Thanks so much for trying it and helping me with the addition! And thanks again to Tom for the original Smiley Happy REALLLLLY APPRECIATE THIS.

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
  • 20 replies
  • 14543 views
  • 9 likes
  • 7 in conversation