LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (June 2004, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Tue, 22 Jun 2004 18:24:34 -0400
Reply-To:   Edney.Shawn@EPAMAIL.EPA.GOV
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Shawn Edney <Edney.Shawn@EPAMAIL.EPA.GOV>
Subject:   Re: Best way to Include data and time in a filename
Content-type:   text/plain; charset=US-ASCII

There is an *undocumented* ISO 8601 SAS format, is8601dtX.X. Using this format I modified Chang's example to come up with timestamp2 and 3 below.

For anyone curious there is comparable informat with the same name. I added a short data step to the code below to show it off as well.

I originally found the iso8601 format and informat while testing the xml libname engine in version 8.2, but now I have version 8.2 and version 9.0 on my pc. I tell you this because the informat doesn't seem to work in 8.2 now, while the format works in both versions. The problem might be due to a hard drive crash I had a couple months ago. I had to reload SAS from scratch and maybe I didn't download the updated 8.2 sxle engine. In short, your results may vary. ; - )

Try running the following code.

%let timestamp1=%sysfunc(Date(),yymmddn8.)T%sysfunc(compress(%sysfunc (Time(),time.),:)); %let timestamp2=%sysfunc(Datetime(),is8601dt26.6); %let timestamp3=%sysfunc(compress(%sysfunc (Datetime(),is8601dt26.0),-:));

%put timestamp1=&timestamp1.; %put timestamp2=&timestamp2.; %put timestamp3=&timestamp3.;

data _null_; _dt_=input("&timestamp2",is8601dt26.6); _dt2_=put(_dt_,datetime21.2); put _dt_=; put _dt2_=; run;

which yields the following in version 9.0

timestamp1=20040622T180658 ---> Mark/Chang's code timestamp2=2004-06-22T18:06:58.062000 timestamp3=20040622T180658

_dt_=1403546818.1 _dt2_=22JUN2004:18:06:58.06

Shawn Edney

Analyst/Programmer CSC

"Chang Y. Chung" <chang_y_chung@HO To: SAS-L@LISTSERV.UGA.EDU TMAIL.COM> cc: Sent by: "SAS(r) Subject: Re: Best way to Include data and time in a filename Discussion" <SAS-L@LISTSERV.U GA.EDU>

06/22/2004 02:09 PM Please respond to "Chang Y. Chung"

On Tue, 22 Jun 2004 10:59:56 -0700, Terjeson, Mark <TERJEM@DSHS.WA.GOV> wrote:

>Hi David, > >One of many schemes is to utilize the decending >order of the units-of-measure so that automatic >sorting of filenames keeps the files in your >directory in chronological order. Sometimes I >may have multiple files per minute, so I take >it down to seconds. e.g. CCYYMMDDHHMMSS > > > >data test; > a=1; >run; > > * CCYYMMDDHHMMSS ; >%let >timestamp=%sysfunc(Date(),yymmddn8.)%sysfunc(compress(%sysfunc(Time (),time.) >,:)); > > >proc export data=test > outfile= "c:\temp\FINAL_&timestamp..xls" > dbms=excel2000 replace; >run;

Hi, Mark,

Beautiful! Adding what ISO 8601 suggests, this could be a one-liner:

%macro timeStamp; %*-- ISO 8601 suggests a latin capital letter T for a separater --*; %*;%sysfunc(Date(),yymmddn8.)T%sysfunc(compress(%sysfunc(Time(),time.),:))

%mend;

%put ***%timeStamp***; /* on log ***20040622T140718*** */


Back to: Top of message | Previous page | Main SAS-L page