BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
arnouxvr
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

6 REPLIES 6
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

See:

Ksharp
Super User

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

arnouxvr
Fluorite | Level 6

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?

Kurt_Bremser
Super User

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.

Kurt_Bremser
Super User

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.

arnouxvr
Fluorite | Level 6

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;

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 6 replies
  • 7289 views
  • 3 likes
  • 4 in conversation