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.
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.
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;
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.
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
Thanks so much for trying it and helping me with the addition! And thanks again to Tom for the original REALLLLLY APPRECIATE THIS.
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!
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.