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

%if "&option"="Y" %then %do;
%make_dlm_file(dataset = base_recs, /* make_dlm_file creates a delimited output file */
filename = "/home/xxxxx/Output_&cntry._&id.txt",
dlmr = "|",
qtes = "no",
header = "no",
label = "no");
run;

Is it possible to add a timestamp to the output file name :- /home/xxxxx/Output_&cntry._&id_<timestamp>.txt

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

Yes, it is.

 

data _null_;   
   call symputx('timestamp', put(datetime(), B8601DT.));
run;

%make_dlm_file(dataset = base_recs, /* make_dlm_file creates a delimited output file */
filename = "/home/xxxxx/Output_&cntry._&id_&timestamp..txt",
dlmr = "|",
qtes = "no",
header = "no",
label = "no");

View solution in original post

5 REPLIES 5
Jagadishkatam
Amethyst | Level 16
Please try the global macro variables
&sysdate9. for date and &systime5. for time
Thanks,
Jag
andreas_lds
Jade | Level 19

Yes, it is.

 

data _null_;   
   call symputx('timestamp', put(datetime(), B8601DT.));
run;

%make_dlm_file(dataset = base_recs, /* make_dlm_file creates a delimited output file */
filename = "/home/xxxxx/Output_&cntry._&id_&timestamp..txt",
dlmr = "|",
qtes = "no",
header = "no",
label = "no");
thomp7050
Pyrite | Level 9

Yes, this is one of my favorite techniques for making a workbook with many sheets:

 

data _null_;
call symputx('nowyear', year(date()));
call symputx('nowmonth', month(date()));
call symputx('nowday', day(date()));
call symputx('nowhour', hour(datetime()));
call symputx('nowminute', minute(datetime()));
run;

%let myvar = %str(&nowyear)_%str(&nowmonth)_%str(&nowday)_%str(&nowhour)_%str(&nowminute); 
%let title = "F:\Main\Studies\ICO_DUALS\EnrollBuckets\Documents\EN_%str(&myvar).xlsx";

PROC EXPORT DATA=RPT_T1 outfile= &title dbms=xlsx replace;
sheet="RPT_T1_TRAN";
run;

You can modify for .txt I believe.  Repeat the proc export for as many as you would like. 

Kurt_Bremser
Super User

@thomp7050 wrote:

Yes, this is one of my favorite techniques for making a workbook with many sheets:

 

data _null_;
call symputx('nowyear', year(date()));
call symputx('nowmonth', month(date()));
call symputx('nowday', day(date()));
call symputx('nowhour', hour(datetime()));
call symputx('nowminute', minute(datetime()));
run;

%let myvar = %str(&nowyear)_%str(&nowmonth)_%str(&nowday)_%str(&nowhour)_%str(&nowminute); 
%let title = "F:\Main\Studies\ICO_DUALS\EnrollBuckets\Documents\EN_%str(&myvar).xlsx";

PROC EXPORT DATA=RPT_T1 outfile= &title dbms=xlsx replace;
sheet="RPT_T1_TRAN";
run;

You can modify for .txt I believe.  Repeat the proc export for as many as you would like. 


Keep in mind that unformatted values for month, day, hours, minutes, seconds may prevent proper sorting of filenames. Use the z2. format to keep a leading zero.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

As a slight away from your question, I note that most people put date/time information in filenames/sheet names etc.  Generally I find this practice to be a bit archaic and too much hard work.  Say you send me a files named XYZ_ddmmmyyyy. txtx, then in a few days another with a different date.  There then has to be faff about what file to use, how to get filename etc.  I would hope that in this day and age all users are using some sort of automated versioning system, and dated filenames just does not fit that at all, you want the next file to have the same filename so you can look at the audit trail of the files.  Just saying this as personally, if I am using a VCS then I would not accept  structural items (filename, column names and such like) changing between files.

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
  • 5 replies
  • 9614 views
  • 3 likes
  • 6 in conversation