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]

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

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
  • 2 replies
  • 1878 views
  • 1 like
  • 3 in conversation