DATA Step, Macro, Functions and more

Store Date Milliseconds

Accepted Solution Solved
Reply
Contributor
Posts: 25
Accepted Solution

Store Date Milliseconds

Is it possible to store a timestamp on a SAS Dataset date column that will contain milliseconds as well?


Accepted Solutions
Solution
‎05-11-2015 08:21 AM
Super User
Posts: 6,932

Re: Store Date Milliseconds

You first have to convert a date column (days from 01jan1960) to a datetime column (seconds from 01jan1960:00:00:00), then you can use the fractional part of the datetime value to store fractions of a second. Use datetime23.3 as format to display milliseconds.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Super User
Super User
Posts: 7,399

Re: Store Date Milliseconds

Hi,

See:

Super User
Posts: 9,676

Re: Store Date Milliseconds

No. Date type variable (integer) is different with DateTime(double) type variable. You should firstly know what kind of variable you should use  .

Message was edited by: xia keshan

Contributor
Posts: 25

Re: Store Date Milliseconds

I just want to make sure about the following:


data timestamp;

  date1 = date();

  date2 = datetime();

run;

date1 contains the number of days from 1 JAN 1960 and date2 contains the number of seconds from midnight 1 JAN 1960.

How do I create a variable date3 that contains the number of milliseconds from 1 JAN 1960?

Super User
Posts: 6,932

Re: Store Date Milliseconds

If you only want to display the total number of milliseconds, just multiply the datetime value by 1000. And use a simple numerical format instead of a datetime format.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Solution
‎05-11-2015 08:21 AM
Super User
Posts: 6,932

Re: Store Date Milliseconds

You first have to convert a date column (days from 01jan1960) to a datetime column (seconds from 01jan1960:00:00:00), then you can use the fractional part of the datetime value to store fractions of a second. Use datetime23.3 as format to display milliseconds.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 25

Re: Store Date Milliseconds

Thanks KurtBremser,

It looks like it is working when I create two data steps in order to "delay" execution I can see that the timestamp per millisecond is different.

data time1;

  date1 = datetime();

run;

data time2;

  date1 = datetime();

run;

data time;

  set time1 time2;

  format date: datetime23.3;

run;

proc print;

run;

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 2038 views
  • 3 likes
  • 4 in conversation