Help using Base SAS procedures

Timestamp

Reply
Occasional Contributor
Posts: 7

Timestamp

Hi,

I need the timestamp in the below format:

2014-09-08-21.45.08.520676

The data part can be obtained by using the data functions and the time using time functions. But i am unable to get the microseconds.

Can someone help me out here with this.

Thanks in advance.

Valued Guide
Posts: 3,208

Re: Timestamp

That is no time it is datetime in SAS words. The timestap is probably coming from a DBMS or OS conventions.

The datetime in SAS are integers measured in seconds fraction of seconds are you microseconds.

Do you want that as string printed out use Formats: SAS(R) 9.4 Formats and Informats: Reference

Do you want to have a conversion, let the conversion do the work.

What is your problem?

---->-- ja karman --<-----
Super User
Posts: 9,662

Re: Timestamp

TimeW.D can display decimal .

data have;
input time stimer12.;
format time time12.2;
cards;
09:02:12
05:04:19.21
;
run;

Xia Keshan

Super Contributor
Posts: 358

Re: Timestamp

Hi:

I use a custom date time format like this:

  proc format;
    picture mydtss low-high = '%Y-%0m-%0d-%0H.%0M.%0S'      (datatype=datetime);
  run;

***************************************************************************************;

data stuff;

a=datetime();

put a 22.2 +5 a mydtss.;

run;

Gives me:               1727341907.42        2014-09-26-09.11.47

You may need to play with it a bit to get all the decimal places for the seconds.

SAS Super FREQ
Posts: 682

Re: Timestamp

As stated before there is the datetime value in SAS.

See Log from SAS program

39         %put NOTE: &=sysvlong &=sysscpl %sysfunc(datetime(), 20.6);

NOTE: SYSVLONG=9.04.01M2P072314 SYSSCPL=X64_7PRO    1727371518.875000

As you see running on windows you get down to milliseconds but not more, might be different on Unix/Linux, can not test now

Bruno

Message was edited by: Bruno Müller

result from running in the SAS University Edition

41 %put NOTE: &=sysvlong &=sysscpl %sysfunc(datetime(), 20.8);

NOTE: SYSVLONG=9.04.01M1P120413 SYSSCPL=Linux 1727351691.72906000

Frequent Contributor
Posts: 78

Re: Timestamp

You may find this thread useful.  Based on my experiments, I would use datetimes if I did not need precisions higher than milliseconds.  If you need microseconds, I would separate the date part from the time part, which essentially gives you 16 bytes (8 for date [more than you need] + 8 for time [precision to nanoseconds, if you need it]).

Ask a Question
Discussion stats
  • 5 replies
  • 832 views
  • 0 likes
  • 6 in conversation