BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi
I have a situation were I need to output my datasets in CSV files with system timestamp. What is the best way to do so? Currently I'm doing a separate macro var to store date from sysdate and then HH and MM from SYStime separately and then combining all three together into an other macro var and then using the same in the outfile of the PROC EXPORT..

Appreciate your help

Edd
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Since you want to generate the date/time as part of your program, the technique using macro variable is reasonable - it also can be done with a DATA step and use CALL SYMPUT to generate the macro variable as needed (format-wise). Here's just one example using macro variables:

%LET file_name_model = node1_node2_DTMyymmddhhmm;
%let date_time = %sysfunc(compress(&SYSDATE&SYSTIME,%str(:)));
%let file_name = %sysfunc(tranwrd(&file_name_model,yymmddhhmm,&date_time));
%put &file_name;

Scott Barry
SBBWorks, Inc.
data_null__
Jade | Level 19
The characters often used in formatted date time values are not usually welcome in filenames. I like to use a PICTURE format to format the date time exactly as I want. Use the PICTURE in the format field of SYSFUNC call to DATATIME. Make sure the default width is correct so there will be no leading spaces.

[pre]
proc format;
picture datestamp (default=15) other='%Y%0m%0dt%0H%0M%0S' (datatype=datetime);
run;
%put datestamp = ***%sysfunc(datetime(),datestamp)***;

proc export replace data=sashelp.class outfile="class%sysfunc(datetime(),datestamp).csv";
run;
[/pre]

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2551 views
  • 1 like
  • 3 in conversation