HI
I am new in sas.
I want to create a folder that displays something like this
SASdata_05SEP2018_1312
the "1312" represents hours and minutes
How do I do this in sas?
This is my code:
options dlcreatedir;
%let todayFolderName = SASdata_%sysfunc(today(),date9.);
libname sas_data "S:\StatsTeam\trialdata\Final analysis\Analysis 2018_08_10\other programs\&todayFolderName\";
libname sas_data clear;
Thanks
Andre
%let date=%sysfunc(today(),date9.) ;
%let hhmm=%sysfunc(compress(%sysfunc(time(),hhmm.),:));
%put &date &hhmm;
data _null_;
rc=dcreate("SASdata_&date._&hhmm",'c:\temp');
run;
And what happens when you run this code (post the log if it does not work as expected)?
Note that
S:\StatsTeam\trialdata\Final analysis\Analysis 2018_08_10\other programs
must already exist, and you need to have the necessary permissions there.
options dlcreatedir;
libname sas_data "S:\StatsTeam\trialdata\Final analysis\Analysis 2018_08_10\other programs\SASdata_%sysfunc(date(),date9.)_%sysfunc(compress(%sysfunc(time(),tod5.),%str( :)))\";
not tested, but that should work in plain macro. Or you could do it in a datastep:
data _null_; length str $200; str=cats("SASData_",put(date(),date9.),"_",compress(put(time(),tod5.),":")); call symputx('fname',str); run;
libname sas_data "S:\StatsTeam\trialdata\Final analysis\Analysis 2018_08_10\other programs\&fname.";
I would however caution against the use of dates/times and other changeable information in folders, files, and paths. I would hope that your using some sort of version control system, or controlled environment, and having this type of changeable naming will break that. Not to mention its harder to program against having to switch libnames and filenames etc.
%let date=%sysfunc(today(),date9.) ;
%let hhmm=%sysfunc(compress(%sysfunc(time(),hhmm.),:));
%put &date &hhmm;
data _null_;
rc=dcreate("SASdata_&date._&hhmm",'c:\temp');
run;
%let date=%sysfunc(today(),date9.) ;
%let hhmm=%sysfunc(compress(%sysfunc(time(),hhmm.),:));
%put &date &hhmm;
data _null_;
rc=dcreate("SASdata_&date._&hhmm",'c:\temp');
run;
Thanks you answered my question
Just one more question
I specified the libname sas_data and tried to put in the in the dcreate function but it does not work
libname sas_data "S:\StatsTeam\trialdata\Final analysis\Analysis 2018_08_10\other programs\";
%let date=%sysfunc(today(),date9.) ;
%let hhmm=%sysfunc(compress(%sysfunc(time(),hhmm.),:));
%put &date &hhmm;
data _null_;
rc=dcreate("SASdata_&date._&hhmm",'sas_data.');
run;
How can I set a path in the very beginning and then refer to it in the dcreate function?
Also, how can I set automatically a new libname that refers to the subdirectory?
The context of this question is the following: I am importing data from a database, and everytime I do it I want to create a folder with time and date the data was imported. Then I want to run the analysis using the folder I have just created. I can do it manually but it would be cumbersome.
So, I want to create my settings in the very beginning, so I don't need to modify them when I import new data with a different date and time
Thanks in advance for any help provided
Andre
In the string for the dcreate function, you need a physical pathname. A library reference does not work there.
You can put the physical path into a macro variable, like you did with the other parts:
%let library_path=S:\StatsTeam\trialdata\Final analysis\Analysis 2018_08_10\other programs;
%let date=%sysfunc(today(),date9.) ;
%let hhmm=%sysfunc(compress(%sysfunc(time(),hhmm.),:));
%put &date &hhmm;
data _null_;
rc=dcreate("SASdata_&date._&hhmm","&library_path.");
run;
library sas_data "&library_path.\SASdata_&date._&hhmm.";
Thanks, it worked but I had to change library to libname
library sas_data "&library_path.\SASdata_&date._&hhmm.";
to
libname sas_data "&library_path.\SASdata_&date._&hhmm.";
Thanks
You need this ?
rc=dcreate("SASdata_&date._&hhmm",'S:\StatsTeam\trialdata\Final analysis\Analysis 2018_08_10\other programs\');
and refer to it :
libname sasdata " S:\StatsTeam\trialdata\Final analysis\Analysis 2018_08_10\other programs\SASdata_&date._&hhmm ";
This is my final code and it works and it was exactly what I needed
%let library_path=C:\x\y\trialdata\Final analysis\Analysis 2018_08_10\other programs;
%let date=%sysfunc(today(),date9.);
%let hhmm=%sysfunc(compress(%sysfunc(time(),hhmm.),:));
%put &date &hhmm;
data _null_;
rc=dcreate("SASdata_&date._&hhmm", "&library_path.");
run;
libname sas_data "&library_path.\SASdata_&date._&hhmm.";
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 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.