Help using Base SAS procedures

sysdate in proc export

Posts: 0

sysdate in proc export

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

Super Contributor
Super Contributor
Posts: 3,174

Re: sysdate in proc export

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(Smiley Happy));
%let file_name = %sysfunc(tranwrd(&file_name_model,yymmddhhmm,&date_time));
%put &file_name;

Scott Barry
SBBWorks, Inc.
Respected Advisor
Posts: 3,777

Re: sysdate in proc export

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.

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

proc export replace data=sashelp.class outfile="class%sysfunc(datetime(),datestamp).csv";
Ask a Question
Discussion stats
  • 2 replies
  • 1 like
  • 3 in conversation