BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
joaolopes
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
%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;

View solution in original post

11 REPLIES 11
Kurt_Bremser
Super User

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.

joaolopes
Calcite | Level 5
It runs and creates a folder with date but I don't know how to put time in the name of the folder
RW9
Diamond | Level 26 RW9
Diamond | Level 26

 

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.

 

 

Cynthia_sas
SAS Super FREQ
Hi:
According to this note: http://support.sas.com/kb/56/710.html you cannot create 2 directories with 1 LIBNAME statement. so first, you need to make a macro variable with your time value and then you'll need to follow the technique in the note to make the directory.

Cynthia
Ksharp
Super User
%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;
Ksharp
Super User
%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;
joaolopes
Calcite | Level 5

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

 

 

Kurt_Bremser
Super User

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.";
joaolopes
Calcite | Level 5

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

Ksharp
Super User

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  "; 

joaolopes
Calcite | Level 5

 

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.";

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 11 replies
  • 3317 views
  • 0 likes
  • 5 in conversation