%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
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_×tamp..txt",
dlmr = "|",
qtes = "no",
header = "no",
label = "no");
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_×tamp..txt",
dlmr = "|",
qtes = "no",
header = "no",
label = "no");
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.
@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.
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.
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.